I'd suggest to write a completion function for your cdgit
function.
Put this file named _cdgit
into a directory which is in your $fpath
, e.g. /usr/share/zsh/site-functions
, then start a new shell instance:
#compdef cdgit local expl local ret=1 [[ CURRENT -eq 2 ]] && _wanted directories expl 'git toplevel directory' \ _path_files -/ -W $(git rev-parse --show-toplevel) && ret=0 return ret
This is borrowed from one of the last lines in the _cd
completion function itself, which is of course much more complex.
Demo:
/usr/src/linux-git/Documentation/x86> cd [TAB] local directory i386/ x86_64/ /usr/src/linux-git/Documentation/x86> cdgit [TAB] git toplevel directory Documentation/ crypto/ include/ lib/ scripts/ usr/ arch/ drivers/ init/ mm/ security/ virt/ block/ firmware/ ipc/ net/ sound/ certs/ fs/ kernel/ samples/ tools/