about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Completion/Zsh/Command/_cd33
2 files changed, 32 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e2435c50..3eac24b12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2008-03-28  Peter Stephenson  <pws@csr.com>
 
+	* 24775: Completion/Zsh/Command/_cd, Doc/Zsh/compsys.yo: improve
+	option handling.
+
 	* users/12739: configure.ac: multiple arguments to --with-term-lib
 	weren't handled properly.
 
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