Create multi-word alias in bash?


I want to create an alias in bash, such that

git diff somefile


git diff --color somefile

But I don’t want to define my own custom alias like

alias gitd = "git diff --color"

because if I get used to these custom alias, then I loose the ability to work on machines which don’t have these mappings.

Edit: It seems bash doesn’t allow multi-word alias. Is there any other alternative solution to this apart from creating the alias?


Better answer (for this specific case).

From git-config man page:

       When set to always, always use colors in patch. When false (or
       never), never. When set to true or auto, use colors only when the
       output is to the terminal. Defaults to false.

No function or alias needed. But the function wrapper approach is general for any command; stick that card up your sleeve.

Answered By – Kaz

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published