1

What I want:

cd c/ra<tab> completes to ~/code/rails-app and cd c/<tab> shows a list of dirs within ~/code


What I currently have:

c ra<tab> completes to c rails-app if I have a directory ~/code/rails-app and c <tab> shows a list of dirs within ~/code

By having this in my .zshrc:

c() { cd ~/code/$1; }
_c() { _files -W ~/code -/; }
compdef _c c


This tool looks promising: https://github.com/flavio/jump but I'd like something more lightweight.

Steve McKinney
  • 3,183
  • 1
  • 23
  • 26

1 Answers1

3

Tab completion such as you've described, at least for directories, should be doable by zsh without the need to write a zsh function.

This link, for example, notes that typing /u/l/b then tab expands to /usr/local/bin on the prompt.

This works for me - if I make a directory ~/code/rails-app such:

zsh% ls ~/code
another-app       another-dir rails-app
zsh% ls ~/code/rails-app
one two

then:

zsh% cd c/ra<TAB> # this expands to 'cd code/rails-app'
zsh% cd c/<TAB><TAB> # Double tab, one to expand "c" to "code", 
zsh% #               # second gives me the zsh-completion menu

I can't point out which zsh option this is - I'm using a fairly heavily modified ~/.zshrc and bits of oh-my-zsh. This might be functionality given by zsh without needing to be enabled; if not, details in either the first link or somewhere in oh-my-zsh or even some version of the ZSH manual should help. (I find the manual a little ... overwhelming, to say the least, though).

I don't believe that you need to write a function to achieve this behaviour - zsh is definitely able to do it.

simont
  • 68,704
  • 18
  • 117
  • 136
  • I settled on using fasd https://github.com/clvv/fasd which is a different way to solve my problem. But thanks, your exactly right Zsh autocomplete has most of the features I was requesting. – Steve McKinney May 17 '12 at 16:39