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.