Pistos
Pistos

Reputation: 23782

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".

Upvotes: 2

Views: 1348

Answers (2)

Zach Kelling
Zach Kelling

Reputation: 53819

A simpler approach:

compdef "_files -W ~/somedir -/" someappname

Upvotes: 5

Pistos
Pistos

Reputation: 23782

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.

Upvotes: 2

Related Questions