我想在fish中定义一些别名。显然,应该可以在

~/.config/fish/functions

但当我重新启动shell时,它们不会自动加载。什么好主意吗?


当前回答

将文件保存为~/.config/fish/functions/{some_function_name}。当你开始钓鱼时,它们应该自动加载。

其他回答

如果没有配置。鱼在~/。Config /fish/,使它。 这里你可以写你的函数。函数名;命令;结束

将文件保存为~/.config/fish/functions/{some_function_name}。当你开始钓鱼时,它们应该自动加载。

对于后人来说,鱼的别名只是函数:

$ 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”

这就是我如何定义一个新函数foo,运行它,并持久地保存它。

sthorne@pearl~> function foo
                    echo 'foo was here'
                end
sthorne@pearl~> foo
foo was here
sthorne@pearl~> funcsave foo

正确地从~/.config/fish/functions加载函数

您可以在文件中只设置一个函数,并且文件名与函数名+添加.fish扩展名相同。

这样更改文件内容在打开的终端中重新加载函数(注意可能会出现一些延迟~1-5s)

这样,如果你通过命令行编辑

function name; function_content; end

then

funcsave name

你有用户定义的功能在控制台和自定义在相同的顺序。