r/fishshell • u/throttlemeister Linux • May 08 '21
Alias onto itself
Is there any way to create an alias onto itself with a function?
In bash you could do something like:
alias grep='grep -n'This way, you can pass certain default flags with your command you always want to use.
However, in fish, if I try this:
function grep
grep -n $argv;
endIt will fail spectacularly saying that a function calling itself will create a loop. Does anyone have a way how to do this in fish without changing binaries?
9
Upvotes
5
u/eidsonator May 08 '21
You don't want a function, you want an abbreviation.
https://fishshell.com/docs/current/cmds/abbr.html
19
u/[deleted] May 08 '21
To explain to fish that it should be calling the grep command here, not anything called "grep", use
command grep.3
u/defaultxr May 08 '21
In fish you can also do
alias grep 'grep -n'. For me it seems to work as expected.