Linux 如何在鱼壳中定义别名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2762994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to define an alias in fish shell?
提问by armandino
I would like to define some aliases in fish. Apparently it should be possible to define them in
我想在fish中定义一些别名。显然应该可以在
~/.config/fish/functions
but they don't get auto loaded when I restart the shell. Any ideas?
但是当我重新启动 shell 时它们不会自动加载。有任何想法吗?
采纳答案by Bozhidar Batsov
Just use alias
. Here's a basic example:
只需使用alias
. 这是一个基本示例:
# 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
.
最后一条命令创建文件~/.config/fish/functions/rmi.fish
.
Interested people might like to find out more about fish aliases in the official manual.
回答by Jerub
This is how I define a new function foo
, run it, and save it persistently.
这就是我定义一个新函数foo
、运行它并持久保存它的方式。
sthorne@pearl~> function foo
echo 'foo was here'
end
sthorne@pearl~> foo
foo was here
sthorne@pearl~> funcsave foo
回答by seaslee
- if there is not config.fishin ~/.config/fish/, make it.
- there you can write your function .
function name; command; end
- 如果没有config.fish在〜/的.config /鱼/,做到这一点。
- 在那里你可以写你的函数。
function name; command; end
回答by martisj
Save your files as ~/.config/fish/functions/{some_function_name}.fish
and they should get autoloaded when you start fish.
将您的文件另存为~/.config/fish/functions/{some_function_name}.fish
,当您开始钓鱼时,它们应该会自动加载。
回答by glenn Hymanman
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”
回答by pawelkl
To properly load functions from ~/.config/fish/functions
从~/.config/fish/functions正确加载函数
You may set only ONEfunction inside file and name file the same as function name + add .fish extension.
您只能在文件中设置一个函数,并将文件命名为与函数名称相同的名称 + 添加 .fish 扩展名。
This way changing file contents reload functions in opened terminals (note some delay may occur ~1-5s)
这种方式在打开的终端中更改文件内容重新加载功能(注意可能会出现一些延迟~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.
您在控制台中拥有用户定义的功能,并以相同的顺序定制。
回答by Mike
make a function in ~/.config/fish/functions called mkalias.fish and put this in
在 ~/.config/fish/functions 中创建一个名为 mkalias.fish 的函数并将其放入
function mkalias --argument key value
echo alias $key=$value
alias $key=$value
funcsave $key
end
and this will create aliases automatically.
这将自动创建别名。
回答by CookAtRice
fish starts by executing commands in ~/.config/fish/config.fish. You can create it if it does not exist:
fish 通过在 ~/.config/fish/config.fish 中执行命令开始。如果它不存在,您可以创建它:
vim ~/.config/fish/config.fish
vim ~/.config/fish/config.fish
and save it with :wq
并保存它 :wq
step1. make configuration file (like .bashrc)
第1步。制作配置文件(如.bashrc)
config.fish
配置文件
step2. just write your alias like this;
第2步。像这样写你的别名;
alias rm="rm -i"
别名 rm="rm -i"
回答by Tobias Mühl
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
而不是一个,alias
你会得到更好的自动完成。在fish中abbr
更接近于bash别名的行为。
abbr -a gco git checkout
Will -a
dd a new abbr
eviation gco
that expands to git checkout
.
将-a
DD新abbr
eviationgco
是扩展到git checkout
。