Save your files as ~/.config/fish/functions/{some_function_name}.fish
and they should get autoloaded when you start fish.
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
make a function in ~/.config/fish/functions called mkalias.fish and put this in
function mkalias --argument key value
echo alias $key=$value
alias $key=$value
funcsave $key
end
and this will create aliases automatically.
To properly load functions from ~/.config/fish/functions
You may set only ONE function inside file and name file the same as function name + add .fish extension.
This way changing file contents reload functions in opened terminals (note some delay may occur ~1-5s)
That way if you edit either by commandline
function name; function_content; end
then
funcsave name
you have user defined functions in console and custom made in the same order.
fish starts by executing commands in ~/.config/fish/config.fish. You can create it if it does not exist:
vim ~/.config/fish/config.fish
and save it with :wq
step1. make configuration file (like .bashrc)
config.fish
step2. just write your alias like this;
alias rm="rm -i"
If you add an abbr
instead of an alias
you'll get better auto-complete. In fish abbr
more closely matches the behavior of a bash alias.
abbr -a gco git checkout
Will -a
dd a new abbr
eviation gco
that expands to git checkout
.
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”
I found the prior answers and comments to be needlessly incomplete and/or confusing. The minimum that I needed to do was:
~/.config/fish/config.fish
. This file can optionally be a softlink.alias myalias echo foo bar
.fish
. To confirm the definition, try type myalias
. Try the alias.function name; command; end
Source: Stackoverflow.com