1

I'm in the process of migrating some tcsh completion settings to zsh and I'm a little lost in the documentation. What I'd like is to complete an argument in one of two ways. If the current word to be completed does not contains a /, it should be one of a set of strings. If it does contains a /, it should be a directory.

This:

_foo() {
    _arguments -C '1:Name:(Name1 Name2 Name3)' '1:Directory:_path_files -/'
}

does not work as it isn't allowed to specify twice the same argument. I played with _regex_arguments but I seem to have missed something there, because I got no behavior which made any sense.

1

I ended up with:

#compdef foo

_foo() {
     local curcontext="$curcontext" state line
     typeset -A opt_args
     _arguments -C '-a' '-b' '-c' '-d' '1: :->name'
     case $state in
         name)
             case $words[2] in
                 */*)
                     _arguments '*:directory:_path_files -/'
                     ;;
                 *)
                     _arguments '*:name:(Name1 Name2 Name3)'
                     ;;
             esac
     esac
}

_foo "$@"

but I'm not sure this is the best solution. In particular, I copied the usage of $words from some examples, but I didn't find it in the documentation.

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.