views:

91

answers:

1

I want to adjust zsh so that I can tab complete:

myprog <tab>

using all *.foo files in ~/somedir, but have it so that it displays them without the .foo extension.

Is there any way to do this?

This is what I have so far:

#compdef myprog
typeset -A opt_args
local context state line
local -a mydirs
mydirs="(. ~/somedir)"

_arguments -s -S \
    "*:name:->foos" \
    && return 0

case $state in
    (foos)
        _files -W ${mydirs} -g '*.foo(:r)' && return 0
    ;;
esac

return 1

However, this displays double the output for every file (that is, each .foo file is listed with and without its extension). Is there any way around this?

+2  A: 

I believe you need to set the file-patterns style, probably using '%p:globbed-files'.

Dennis Williamson
Would you mind extending upon this answer a bit? I'm not entirely familiar with zsh's completion syntax, and am having trouble deducing where to start with this.
meeselet
Nvm, got it: `zstyle ':completion:*' file-patterns '%p:globbed-files:'` belongs in my .zshrc. Thanks!
meeselet