diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2008-03-28 14:44:42 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2008-03-28 14:44:42 +0000 |
commit | 594f783c77e89a1b4d7c1b58448f797e7ed87e43 (patch) | |
tree | 74451ed615651548358e1e3d9264f60d38b57a65 /Completion/Zsh/Command | |
parent | 0db1d3f8396945324208dea0ef01ad828c149932 (diff) | |
download | zsh-594f783c77e89a1b4d7c1b58448f797e7ed87e43.tar.gz zsh-594f783c77e89a1b4d7c1b58448f797e7ed87e43.tar.xz zsh-594f783c77e89a1b4d7c1b58448f797e7ed87e43.zip |
24775: improve _cd option handling
Diffstat (limited to 'Completion/Zsh/Command')
-rw-r--r-- | Completion/Zsh/Command/_cd | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/Completion/Zsh/Command/_cd b/Completion/Zsh/Command/_cd index 3c19f82da..d2632b215 100644 --- a/Completion/Zsh/Command/_cd +++ b/Completion/Zsh/Command/_cd @@ -11,17 +11,37 @@ # it's not a lot of use. If you don't type the + or - it will # complete directories as normal. +_cd_options() { + _arguments -s \ + '-q[Quiet, no output or use of hooks]' \ + '-s[Refuse to use paths with symlinks]' \ + '(-P)-L[Retain symbolic links ignoring CHASE_LINKS]' \ + '(-L)-P[Resolve symbolic links as CHASE_LINKS]' +} + setopt localoptions nonomatch -local expl ret=1 +local expl ret=1 curarg +integer argstart=2 noopts + +if (( CURRENT > 1 )); then + # if not in command position, may have options. + # Careful: -<-> is not an option. + while [[ $words[$argstart] = -* && argstart -lt CURRENT ]]; do + curarg=$words[$argstart] + [[ $curarg = -<-> ]] && break + (( argstart++ )) + [[ $curarg = -- ]] && noopts=1 && break + done +fi -if [[ CURRENT -eq 3 ]]; then +if [[ CURRENT -eq $((argstart+1)) ]]; then # cd old new: look for old in $PWD and see what can replace it local rep # Get possible completions using word in position 2 - rep=(${~PWD/$words[2]/*}~$PWD(-/)) + rep=(${~PWD/$words[$argstart]/*}~$PWD(-/)) # Now remove all the common parts of $PWD and the completions from this - rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}}) + rep=(${${rep#${PWD%%$words[$argstart]*}}%${PWD#*$words[$argstart]}}) (( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep else # Complete directory stack entries with ~ or when not in command position @@ -70,6 +90,11 @@ else [[ CURRENT -ne 1 || ( -z "$path[(r).]" && $PREFIX != */* ) ]] && alt=( "${cdpath+local-}directories:${cdpath+local }directory:_path_files -/" "$alt[@]" ) + if [[ CURRENT -eq argstart && noopts -eq 0 && $PREFIX = -* ]] && + zstyle -t ":completion:${curcontext}:options" complete-options; then + alt=("$service-options:$service option:_cd_options" "$alt[@]") + fi + _alternative "$alt[@]" && ret=0 return ret |