`bind` 没有 运行 用户定义函数
`bind` does not run user-defined function
fish 文档说您可以 运行 使用语法
的命令列表
bind <char> cmd1 cmd2 ...
包括 https://fishshell.com/docs/current/commands.html#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。
解决方法是在用户定义的函数中使用 commandline -f [function]
语法来访问那些特别适用于 fish_user_key_bindings
的函数:
function on_ampersand
commandline -f backward-delete-char # or whatever
[your code]
end
fish 文档说您可以 运行 使用语法
的命令列表bind <char> cmd1 cmd2 ...
包括 https://fishshell.com/docs/current/commands.html#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。
解决方法是在用户定义的函数中使用 commandline -f [function]
语法来访问那些特别适用于 fish_user_key_bindings
的函数:
function on_ampersand
commandline -f backward-delete-char # or whatever
[your code]
end