I am trying to write some completions for an in-house tool. We'll call it thetool
.
Lots of the commands to thetool
do not take a 'file' as an argument. I thought that --no-files
and/or --exclusive
would do this for me but I don't seem to be able to get it to work.
In other words how can I write completions so that the following command does show files in the tab completion
$ thetool file-command *hit-tab*
while the following command does NOT show files in the tab completion
$ thetool non-file-command *hit-tab*
Let's try for a toy example:
$ 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'
now try the completions out:
$ thetool *hit-tab*
file-command (file-command) non-file-command (non-file-command)
Looks good so far...
$ 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/
SEE! What are all those file suggestions doing there?!
Let's try again:
$ 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/
arrrg can someone help me understand what is going on and what I'm doing wrong?