题
我想定义鱼类中的一些别名。显然应该可以定义它们
~/.config/fish/functions
但是当我重新启动外壳时,它们不会自动加载。有任何想法吗?
解决方案
只是使用 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
最后一个命令创建文件 ~/.config/fish/functions/rmi.fish
.
有兴趣的人可能想了解有关鱼类别名的更多信息 官方手册.
其他提示
这就是我定义新功能的方式 foo
, ,运行它,并持续保存。
sthorne@pearl~> function foo
echo 'foo was here'
end
sthorne@pearl~> foo
foo was here
sthorne@pearl~> funcsave foo
对于后代,鱼类别名只是功能:
$ alias foo="echo bar"
$ type foo
foo is a function with definition
function foo
echo bar $argv;
end
删除它
$ unalias foo
/usr/bin/unalias: line 2: unalias: foo: not found
$ functions -e foo
$ type foo
type: Could not find “foo”
- 如果没有 config.fish 在 〜/.config/fish/, , 做了。
- 在那里您可以编写您的功能。
function name command end
将文件保存为 ~/.config/fish/functions/{some_function_name}.fish
当您开始钓鱼时,它们应该会自动加载。
从中正确加载功能 〜/.Config/Fish/功能
您只能设置 一 函数文件和名称文件与函数名称 +添加.fish扩展名相同。
这样,更改文件内容重新加载函数在打开的终端中重新加载函数(注意可能发生一些延迟〜1-5s)
这样,如果您由Commandline编辑
function name; function_content; end
然后
funcsave name
您在控制台中具有用户定义的功能,并按照相同的顺序进行自定义。
鱼首先在〜/.config/fish/config.fish中执行命令。如果不存在,则可以创建它。
步骤1。制作配置文件(例如.bashrc)
config.fish
第2步。像这样写你的别名;
别名rm =“ rm -i”
如果您添加 abbr
而不是一个 alias
您将获得更好的自动完成。在鱼中 abbr
更紧密地匹配狂欢别名的行为。
abbr -a gco git checkout
将要 -a
DD新 abbr
探测 gco
扩展到 git checkout
.
在〜/.config/fish/functions中发挥功能,称为mkalias.s.fish,然后将其放入
function mkalias --argument key value
echo alias $key=$value
alias $key=$value
funcsave $key
end
这将自动创建别名。
不隶属于 StackOverflow