1

Currently I have this and it works as expected if I use it like addcommit 'test commit' but if I use it as addcommit test commit it only sees the first word test. Ideally I'd like to have the functionality of addcommit test commit and it executing git add . && git commit -m 'test commit'

addcommit()
{   
    git add . && git commit -m "$1"
}

PS. I don't understand how the "$1" works in this case, maybe that would be a good starting point to understanding how this should work.

1 Answer 1

3

Replace "$1" with "$*".

And in order to be completely safe against IFS traps:

addcommit()
{
   local IFS=' '
   git add . && git commit -m "$*"
}

This is a case where an alias could help, and allow the commit message to contain any character:

alias addcommit='_m=$(fc -nl -0); git add . && git commit -m "${_m#*addcommit }" #'

addcommit $foo * $bar
# will use the literal "$foo * $bar" message, without expanding it

(works in bash and ksh93)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .