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

~/.config/fish/functions

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


当前回答

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

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

其他回答

使用别名即可。这里有一个基本的例子:

# Define alias in shell
alias rmi "rm -i"

# Define alias in config file ( `~/.config/fish/config.fish` )
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

我发现之前的回答和评论是不必要的不完整和/或混乱。我至少需要做的是:

创建~ / config /鱼/ config.fish。该文件可以是软链接。 添加行别名myalias echo foo bar。 重启鱼。要确认定义,请尝试输入myalias。试试这个别名。

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

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