fish - `bind` 不运行用户定义函数

标签 fish

fish 文档说您可以使用语法运行命令列表

bind <char> cmd1 cmd2 ...

包括https://fishshell.com/docs/current/commands.html#bind中列出的一些特殊命令.

编写具有键绑定(bind)的插件,

我添加

bind '&' `backward-delete-char` on_ampersand

fish_user_key_bindings.fish ,但它没有导致任何行为 - on_ampersand函数没有被调用,backward_delete_char 也没有被调用。 。没有on_ampersand , 有用。

文档没有说明为什么会发生这种行为。

最佳答案

这是 Fish 中的一个错误 - 您无法将输入缓冲区编辑命令与您自己的命令结合起来。请参阅https://github.com/fish-shell/fish-shell/issues/3683 .

解决方法是在用户定义的函数中使用命令行 -f [function] 语法来访问那些专门供 fish_user_key_bindings 使用的函数:

function on_ampersand
    commandline -f backward-delete-char # or whatever
    [your code]
end

关于fish - `bind` 不运行用户定义函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45533272/

相关文章:

fish - 在 Fish Shell 中抑制或自定义介绍消息

fish - iTerm2 上的新 fish session get (standard_in) 1 : parse error

function - 如何从fishshell中删除函数而不直接删除函数文件?

shell - 如何使用 fish shell 从我的 PATH 环境变量中删除特定变量

fish - 如何在fish shell脚本中设置环境变量

macos - Fish Interactive Shell 完整路径

python - 如何在使用 fish 时停用 venv?

git - 使用 && 的 Fishshell 别名

windows - 共享 ssh-agent - Windows 服务、msys2 shell

bash - 如何在fish shell中隐藏某些扩展名的文件?