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.
Tab completion such as you’ve described, at least for directories, should be doable by
zshwithout the need to write azshfunction.This link, for example, notes that typing
/u/l/bthen tab expands to/usr/local/binon the prompt.This works for me – if I make a directory
~/code/rails-appsuch:then:
I can’t point out which
zshoption this is – I’m using a fairly heavily modified~/.zshrcand bits ofoh-my-zsh. This might be functionality given byzshwithout needing to be enabled; if not, details in either the first link or somewhere inoh-my-zshor 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 –
zshis definitely able to do it.