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?

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

1 Answer 1

8

use a shell routine

gdiff() { 
   git diff --color=always "$@" | less -r
}
2
  • Perfect! I'll put this in my .profile
    – AvL
    Commented Oct 5, 2012 at 8:19
  • 1
    Known as functions. Commented Oct 5, 2012 at 14:29

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