1

I have at the moment a completion function that looks something like this (except way more entries)

_arguments \
  '-check[do a check]' \
  '-play[play a specific song]:songnumber' \
  '-test.n=[run test specified number of times]:n' \
  '-test.dir=[run test in a specific working dir]:dir: _path_files -/' \
  '-test.v[run tests verbose]' \
  '-log[delete all log files]' \
  '*:inputfiles: _files'

upon tabbing this leads to printout like that:

pseyfert@robusta:~ > program -⇥
option:
-check     -- do a check
-log       -- delete all log files
-play      -- play a specific song
-test.dir  -- run test in a specific working dir
-test.n    -- run test specified number of times
-test.v    -- run tests verbose

One pattern is that a considerable number of options starts with -test. and I am often not interested in them, so when looking for an option that I don't know by heart, the entire -test. block is somewhat spam. I'd prefer to group the options to a printout like that:

pseyfert@robusta:~ > program -⇥
option:
-check     -- do a check
-log       -- delete all log files
-play      -- play a specific song
-test.     -- test options

and then when reaching -test. reveal what's behind:

pseyfert@robusta:~ > program -test.⇥
option:
-test.dir  -- run test in a specific working dir
-test.n    -- run test specified number of times
-test.v    -- run tests verbose

I realized I can get in the right direction with a minus after the option

_arguments \
  '-check[do a check]' \
  '-play[play a specific song]:songnumber' \
  '-log[delete all log files]' \
  '-test.-[test options]:testopts: _testopts' \
  '*:inputfiles: _files'

such that no space gets added after -test. and a space will not be interpreted as "option continues". What I lack in my repertoire is the _testopts function. I'm tempted to use _arguments again, but that requires leading - after the -test.. With _values I am not aware of a method to place the descriptions and don't know how to continue into other functions like _path_files -/ above.

Are there any examples for gradual option revealing or hints how to best change the design of my completion?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.