0

If I type this inside a regular interactive zsh shell that I have prepared with autoload -U compinit && compinit:

$ cat --

and then press the Tab key on my keyboard, I get this zsh completion output:

$ cat --
--help              -- display help and exit
--number            -- number all output lines
--number-nonblank   -- number nonempty output lines, overrides -n
--show-all          -- equivalent to -vET
--show-ends         -- display $ at end of each line
--show-nonprinting  -- use ^ and M- notation, except for LFD and TAB
--show-tabs         -- display TAB characters as ^I
--squeeze-blank     -- suppress repeated empty output lines
--version           -- output version information and exit

Q: How can I trigger this output with a regular command via zsh -c ...?

I tried a few different ways, but so far I have not been able to figure out how to do this. The "natural" approach does not work:

$ zsh -c "autoload -U compinit && compinit && cat --$'\t'"
cat: unrecognized option '--    '
Try 'cat --help' for more information.

Neither does trying to use zle -U:

$ zsh -c "autoload -U compinit && compinit && zle -U \"cat --$'\t'\""
zsh:zle:1: can only be called from widget function
Enselic
  • 4,434
  • 2
  • 30
  • 42
  • Googling for "test zsh completion" made me find this which contains enough info to solve my problem: https://stackoverflow.com/questions/65386043/unit-testing-zsh-completion-script. This question should be closed as a duplicate. – Enselic Mar 10 '23 at 07:07

0 Answers0