Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by jasonwryan, phunehehe, Renan, warl0ck, Mat Oct 6 '12 at 15:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
@manatwork thanks for the clarification on the right term. I updated question & tag –  AvL Oct 5 '12 at 8:27
    
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

1 Answer 1

up vote 4 down vote accepted

use a shell routine

gdiff() { 
   git diff --color=always "$@" | less -r
}
share|improve this answer
    
Perfect! I'll put this in my .profile –  AvL Oct 5 '12 at 8:19
    
Known as functions. –  glenn jackman Oct 5 '12 at 14:29

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