Search code examples
zshtabscompletiontab-completion

Programming customized tab completion for zsh


Sorry if my google fu is too weak, but: I simply want to adjust zsh so that I can tab complete

someappname -s

using the contents (filenames) of ~/somedir

For example:

someapp -s f<tab>

should cycle through completions based on the files starting with the letter f in ~/somedir . So I might end up with a command line like: "someapp -s foobar".


Solution

  • Well, I worked this out: (source at github)

    #compdef diakonos
    
    typeset -A opt_args
    local context state line
    local sessiondir
    sessiondir=${HOME}/.diakonos/sessions
    
    _arguments -n -s -S \
      "-s[specify session]:session:_files -W $sessiondir" \
      "*:file:_files" \
      && return 0
    
    return 1
    

    I referenced http://www.linux-mag.com/id/1106 ([free] registration required to read), and got help from #zsh on freenode.