我正试图为一个内部工具编写一些补件。我们叫它thetool。
thetool的许多命令都不以“file”作为参数。我以为--no-files和/或--exclusive会为我做这件事,但我似乎无法让它发挥作用。
换句话说,我如何编写完成,以便下面的命令在选项卡完成中显示文件
$ thetool file-command *hit-tab*下面的命令不会在选项卡完成中显示文件
$ thetool non-file-command *hit-tab*让我们来看看一个玩具例子:
$ function thetool
echo $argv
end
$ complete --command thetool --no-files --condition "not __fish_seen_subcommand_from file-command non-file-command" --arguments "file-command" --description "file-command"
$ complete --command thetool --no-files --condition "not __fish_seen_subcommand_from file-command non-file-command" --arguments "non-file-command" --description "non-file-command"
$ complete --command thetool
complete --no-files thetool -d non-file-command -a non-file-command -n 'not __fish_seen_subcommand_from file-command non-file-command'
complete --no-files thetool -d file-command -a file-command -n 'not __fish_seen_subcommand_from file-command non-file-command'现在,尝试完成:
$ thetool *hit-tab*
file-command (file-command) non-file-command (non-file-command)目前看来还不错..。
$ thetool non-file-command *hit-tab*
bin/ dev.yml Judgment.lock README.md TODO.md
completion_test.fish exe/ lib/ shipit.production.yml vendor/
completion_test.zsh Gemfile linters/ sorbet/ zsh_completions.sh
coverage/ Gemfile.lock Rakefile test/ 看见!那些文件建议是怎么回事?!
我们再试一次:
$ complete --command thetool --force-files --condition "not __fish_seen_subcommand_from file-command non-file-command" --arguments "file-command" --erase
$ complete --command thetool --force-files --condition "not __fish_seen_subcommand_from file-command non-file-command" --arguments "file-command"
$ complete --command thetool --no-files --condition "not __fish_seen_subcommand_from file-command non-file-command" --arguments "non-file-command"
$ complete --command thetool
complete --no-files thetool -a non-file-command -n 'not __fish_seen_subcommand_from file-command non-file-command'
complete --force-files thetool -a file-command -n 'not __fish_seen_subcommand_from file-command non-file-command'
$ thetool *hit-tab*
bin/ dev.yml Gemfile.lock non-file-command sorbet/ zsh_completions.sh
completion_test.fish exe/ Judgment.lock Rakefile test/
completion_test.zsh file-command lib/ README.md TODO.md
coverage/ Gemfile linters/ shipit.production.yml vendor/ 谁能帮我弄清楚发生了什么和我做错了什么?
发布于 2022-07-28 17:17:36
如果fish已经看到non-file-command,您就不会调用它来禁用文件。
让我们通过他们:
complete --command thetool --no-files --condition "not __fish_seen_subcommand_from file-command non-file-command" --arguments "file-command" --description "file-command"鱼儿见过non-file-command,病情是假的。
complete --command thetool --no-files --condition "not __fish_seen_subcommand_from file-command non-file-command" --arguments "non-file-command" --description "non-file-command"鱼儿见过non-file-command,病情是假的。
complete --command thetool这没什么用。
complete --no-files thetool -d non-file-command -a non-file-command -n 'not __fish_seen_subcommand_from file-command non-file-command'鱼儿见过non-file-command,病情是假的。
complete --no-files thetool -d file-command -a file-command -n 'not __fish_seen_subcommand_from file-command non-file-command'鱼儿见过non-file-command,病情是假的。
没有禁用文件的条件是真的,所以我们默认启用它们。如果给出了non-file-command,没有什么可以告诉它禁用文件的。
添加
complete --command thetool --no-files --condition " __fish_seen_subcommand_from non-file-command"而且会成功的。
或者,如果您有很多东西不需要文件,而只需要一些文件,那么您可以添加
complete --command thetool --no-files这将始终禁用文件(它没有任何条件,所以只要您正在完成thetool,它就永远是正确的),然后强制对那些这样做的情况使用文件。
complete --command thetool --condition "__fish_seen_subcommand_from file-command" --force-fileshttps://unix.stackexchange.com/questions/711637
复制相似问题