I would like to define some aliases in fish. Apparently it should be possible to define them in
~/.config/fish/functions
but they don't get auto loaded when I restart the shell. Any ideas?
I would like to define some aliases in fish. Apparently it should be possible to define them in
~/.config/fish/functions
but they don't get auto loaded when I restart the shell. Any ideas?
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.
alias local "set -l"
;-(
– user1115652
Apr 18 '14 at 13:43
~/.config/fish/config.fish
so it loads every time I run a terminal.
– Ira Herman
Feb 1 '16 at 22:41
"$argv"
to handle arguments with spaces like we do with bash "$@"
?
– kyb
Jan 18 at 19:30
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
funcsave {some_function_name}
will save it in ~/.config/fish/functions/{some_function_name}.fish
– Hjulle
Aug 22 '14 at 8:48
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”
funcsave foo
. This will save the function into ~/.config/fish/functions/foo.fish
, where fish will automatically load it the first time it is called from a new session.
– Lucretiel
Oct 26 '15 at 14:58
function name command end
Save your files as ~/.config/fish/functions/{some_function_name}.fish
and they should get autoloaded when you start fish.
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.
step1. make configuration file (like .bashrc)
config.fish
step2. just write your alias like this;
alias rm="rm -i"
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.
Open vim .config/fish/conf.d/omf.fish
, bind your bash defines and restart the fish terminal.