首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >鱼类完成-如何防止文件完成?

鱼类完成-如何防止文件完成?
EN

Unix & Linux用户
提问于 2022-07-28 16:45:03
回答 1查看 181关注 0票数 3

我正试图为一个内部工具编写一些补件。我们叫它thetool

thetool的许多命令都不以“file”作为参数。我以为--no-files和/或--exclusive会为我做这件事,但我似乎无法让它发挥作用。

换句话说,我如何编写完成,以便下面的命令在选项卡完成中显示文件

代码语言:javascript
复制
$ thetool file-command *hit-tab*

下面的命令不会在选项卡完成中显示文件

代码语言:javascript
复制
$ thetool non-file-command *hit-tab*

让我们来看看一个玩具例子:

代码语言:javascript
复制
$ 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'

现在,尝试完成:

代码语言:javascript
复制
$ thetool *hit-tab*
file-command  (file-command)  non-file-command  (non-file-command)

目前看来还不错..。

代码语言:javascript
复制
$ 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/                  

看见!那些文件建议是怎么回事?!

我们再试一次:

代码语言:javascript
复制
$ 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/  

谁能帮我弄清楚发生了什么和我做错了什么?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2022-07-28 17:17:36

如果fish已经看到non-file-command,您就不会调用它来禁用文件。

让我们通过他们:

代码语言:javascript
复制
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,病情是假的。

代码语言:javascript
复制
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,病情是假的。

代码语言:javascript
复制
complete --command thetool

这没什么用。

代码语言:javascript
复制
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,病情是假的。

代码语言:javascript
复制
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,没有什么可以告诉它禁用文件的。

添加

代码语言:javascript
复制
complete --command thetool --no-files --condition " __fish_seen_subcommand_from non-file-command"

而且会成功的。

或者,如果您有很多东西不需要文件,而只需要一些文件,那么您可以添加

代码语言:javascript
复制
complete --command thetool --no-files

这将始终禁用文件(它没有任何条件,所以只要您正在完成thetool,它就永远是正确的),然后强制对那些这样做的情况使用文件。

代码语言:javascript
复制
complete --command thetool --condition "__fish_seen_subcommand_from file-command" --force-files
票数 2
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/711637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档