Define an alias in fish shell
Solution 1:
Just use alias
. Here's a basic example:
# Define alias in shell
alias rmi "rm -i"
# Define alias in config file
alias rmi="rm -i"
# This is equivalent to entering the following function:
function rmi
rm -i $argv
end
# Then, to save it across terminal sessions:
funcsave rmi
This last command creates the file ~/.config/fish/functions/rmi.fish
.
Interested people might like to find out more about fish aliases in the official manual.
Solution 2:
This is how I define a new function foo
, run it, and save it persistently.
sthorne@pearl~> function foo
echo 'foo was here'
end
sthorne@pearl~> foo
foo was here
sthorne@pearl~> funcsave foo
Solution 3:
For posterity, fish aliases are just functions:
$ alias foo="echo bar"
$ type foo
foo is a function with definition
function foo
echo bar $argv;
end
To remove it
$ unalias foo
/usr/bin/unalias: line 2: unalias: foo: not found
$ functions -e foo
$ type foo
type: Could not find “foo”