3

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?

AvL
  • 195
  • 2
  • 7
  • @manatwork thanks for the clarification on the right term. I updated question & tag – AvL Oct 05 '12 at 08: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 05 '12 at 12:37

1 Answers1

8

use a shell routine

gdiff() { 
   git diff --color=always "$@" | less -r
}
Julian
  • 909
  • 5
  • 5