Bash – User Input to Bash Alias

aliasbashgit

Whenever I'm using git, I generally add, commit, and push at the same time. So I created an alias in bash to make it simpler:

alias acp='git add -A;git commit -m "made changes";git push'

How do I make it so that the I can change the commit message from "made changes" to something else while I'm running the acp command? For example:

acp "added the Timer Class" 

The above I would want to run everything that the acp command does and make "added the timer class" the commit message. How would I do that?

Thanks!

Best Answer

An alias cannot accept parameters, so you need to create a function:

acp ()
{
        git add -A;git commit -m "$1";git push
}

as always, store it in ~/.bashrc and source it with source ~/.bashrc.

Or better (good hint, binfalse) to avoid performing a command if the previous was not successful, add && in between them:

acp ()
{
        git add -A && git commit -m "$1" && git push
}

Execute it with

acp "your comment"

It is important that you use double quotes, otherwise it will just get the 1st parameter.