How to remove the file extension in a zsh completion?

Posted by meeselet on Stack Overflow See other posts from Stack Overflow or by meeselet
Published on 2010-03-23T15:28:11Z Indexed on 2010/03/23 15:33 UTC
Read the original article Hit count: 242

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?

© Stack Overflow or respective owner

Related posts about zsh

Related posts about completion