0

I have

git () { [ $1 = commit ] && command git commit -v "${@:2}" || command git "$@"; }

It makes git commit have -v as a default, otherwise pass on the params and do whatever the git command is.

But it seems like something that could be shortened?

fyi, I'm slimming down my .bashrc file. Down to 28 (mostly readable still) lines so far.

5

Here's a way to not repeat then command git part:

git () {
    if [ "$1" = commit ]; then set commit -v "${@:2}"; fi
    command git "$@"
}

Note that you should not use $1 without double quotes. Always use double quotes around variable substitutions unless you know why you need to leave them out.

Don't use && and || as shortcuts. It's cute, and it might save a few characters, but saving characters is pointless. Readability is important, and if states the intent of the code in a clearer way.

You may want to define an alias in your git configuration instead (but you can't shadow an existing command this way, you need to use a different name), with something like this in ~/.gitconfig:

[alias]
co = commit -v

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.