[Home] Zsh logo

cdmatch

Zsh Wizard

Download cdmatch Return to Examples
  1. # Start of cdmatch.
  2. # Save in your functions directory and autoload, then do
  3. # compctl -x 'S[/][~][./][../]' -g '*(-/)' - \
  4. # 'n[-1,/], s[]' -K cdmatch -S '/' -- cd pushd
  5. #
  6. # Completes directories for cd, pushd, ... anything which knows about cdpath.
  7. # You do not have to include `.' in your cdpath.
  8. #
  9. # It works properly only if $ZSH_VERSION > 3.0-pre4. Remove `emulate -R zsh'
  10. # for all other values of $ZSH_VERSION > 2.6-beta2. For earlier versions
  11. # it still works if RC_EXPAND_PARAM is not set or when cdpath is empty.
  12. emulate -R zsh
  13. setopt localoptions
  14. local narg pref cdp
  15. read -nc narg
  16. read -Ac pref
  17. cdp=(. $cdpath)
  18. reply=( ${^cdp}/${pref[$narg]%$2}*$2(-/DN^M:t) )
  19. return
  20. # End of cdmatch.