How to define an alias in fish shell?
我想在鱼中定义一些别名。 显然应该可以在中定义它们
1 | ~/.config/fish/functions |
但是当我重新启动shell时,它们不会自动加载。 有任何想法吗?
只需使用
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 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 |
最后一个命令创建文件
有兴趣的人可能想在官方手册中找到更多关于鱼类别名的信息。
这就是我定义一个新函数
1 2 3 4 5 6 | sthorne@pearl~> function foo echo 'foo was here' end sthorne@pearl~> foo foo was here sthorne@pearl~> funcsave foo |
对于后代,鱼别名只是功能:
1 2 3 4 5 6 | $ alias foo="echo bar" $ type foo foo is a function with definition function foo echo bar $argv; end |
要删除它
1 2 3 4 5 | $ unalias foo /usr/bin/unalias: line 2: unalias: foo: not found $ functions -e foo $ type foo type: Could not find"foo" |
将文件保存为
要正确加载?/ .config / fish / functions中的函数
您可以在文件和名称文件中仅设置一个函数与函数名称+添加.fish扩展名相同。
这样改变打开的终端中的文件内容重载功能(注意可能会发生一些延迟~1-5s)
这样,如果您通过命令行编辑
1 | function name; function_content; end |
然后
1 | funcsave name |
您在控制台中具有用户定义的功能,并以相同的顺序定制。
fish通过执行?/ .config / fish / config.fish中的命令开始。
如果它不存在,您可以创建它。
步骤1。制作配置文件(如.bashrc)
config.fish
第2步。只需写下你的别名;
alias rm="rm -i"
如果添加
1 | abbr -a gco git checkout |
将
以下是自动完成功能的视频演示
在?/ .config / fish /函数中创建一个名为mkalias.fish的函数并将其放入
1 2 3 4 5 | function mkalias --argument key value echo alias $key=$value alias $key=$value funcsave $key end |
这将自动创建别名。