Is it possible to use a parameter within an alias command

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

use a shell routine

gdiff() { 
   git diff --color=always "<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b99df9">[email protected]</a>" | less -r
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x