2

I have written a small shell script that takes a single command line argument.

I'd like to be able to autocomplete when I start writing an argument, the autocompletion choices should come from a specific text file.

For instance if my text file contains

foo
foobar

if I start writing my-cli fo and press TAB I like zsh to show me the choices foo and foobar.

Any pointer to a relevant documentation or tutorial is welcome.

0

I am struggling with a similar problem, but a bit more complicated. With a static autocomplete options file the following code works for me:

#compdef test

_test_comp(){
 t=($(cat /tmp/file_with_opts))
 _wanted t expl "availavle options" compadd -a t
}

_arguments -C -S  \
 '*:test_autocomplete:_test_comp'

This way script test will pickup options from /tmp/file_with_opts

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.