10

zsh has a completion system, activated by pressing tab:

llama@llama:~$ git st<Tab>
Completing main porcelain command
stash -- stash away changes to dirty working directory
status -- show working-tree status
Completing plumbing internal helper command
stripspace -- filter out empty lines

All I've been able to figure out is that this comes from the script /usr/share/zsh/functions/Completion/Unix/_git, where _git is the completion command being called.

Assuming I know the name of the completion function (e.g. _git), how could I get the output of what would happen if I entered a certain string and pressed tab? Essentially, I'm trying to take an input of ex. git st and get the output above (programmatically, from a script).

There are many other existing questions about this for bash, but I haven't found anything explaining how to achieve this with zsh.

asked Jun 25, 2016 at 14:43
1

1 Answer 1

7

This can be done by using zsh-capture-completion. The repository's README.md file provides several examples:

capture.zsh 'vim -'
capture.zsh 'vim --'
capture.zsh 'vim --r'
capture.zsh 'echo *('
capture.zsh 'scp hostname:'

Note that the package itself states that it is a proof of concept, and as such may contain errors in its execution.

answered Jan 25, 2018 at 4:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.