Possible Duplicate:
How to pass parameters to an alias?

As answered in Can less retain colored output? I want to use
git diff --color=always filename | less -r to get a colored output of my git diffs. Since I use this a lot it would be nice to set up an alias for this. But how to include the filename in this command?

I tried the following without success:

alias gdiff='git diff --color=always $1 | less -r'

Typing gdiff example.php displays the content of example.php with less but ignores the diff part.

Any ideas?

  • @manatwork thanks for the clarification on the right term. I updated question & tag – AvL Oct 5 '12 at 8:27
  • 1
    Even though the parameter doesn't work in the alias, just something to remember - a parameter won't be expanded inside single quotes, so if this was to work (say you were using directly on the command line with some other defined parameter) it would need to be in double quotes – Drake Clarris Oct 5 '12 at 12:37

use a shell routine

gdiff() { 
   git diff --color=always "$@" | less -r

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