summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-20 08:04:56 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-04-20 08:04:56 +0000
commitc9bedcd98923cd9890bd5d92ec5b0ada57bccc31 (patch)
treec2cf4335940026af58d3d946bf16e70ccf773031 /Completion
parenta903dcba4f0c0ae7b0b80d60604c8a30825aa4e1 (diff)
downloadzsh-c9bedcd98923cd9890bd5d92ec5b0ada57bccc31.tar.gz
zsh-c9bedcd98923cd9890bd5d92ec5b0ada57bccc31.tar.xz
zsh-c9bedcd98923cd9890bd5d92ec5b0ada57bccc31.zip
default values for styles in _expand_word, listing expansions with ^Xd, _expand uses add-space style (10854)
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Commands/_expand_word13
-rw-r--r--Completion/Core/_expand44
2 files changed, 50 insertions, 7 deletions
diff --git a/Completion/Commands/_expand_word b/Completion/Commands/_expand_word
new file mode 100644
index 000000000..9b71dc830
--- /dev/null
+++ b/Completion/Commands/_expand_word
@@ -0,0 +1,13 @@
+#compdef -K _expand_word complete-word \C-xe _list_expansions list-choices \C-xd
+
+# Simple completion front-end implementing expansion.
+
+local curcontext="$curcontext"
+
+if [[ -z "$curcontext" ]]; then
+  curcontext="expand-word:::"
+else
+  curcontext="expand-word:${curcontext#*:}"
+fi
+
+_main_complete _expand
diff --git a/Completion/Core/_expand b/Completion/Core/_expand
index eff8d8601..2557af884 100644
--- a/Completion/Core/_expand
+++ b/Completion/Core/_expand
@@ -28,7 +28,8 @@ exp=("$word")
 # First try substitution. That weird thing spanning multiple lines
 # changes quoted spaces, tabs, and newlines into spaces.
 
-zstyle -s ":completion:${curcontext}:" substitute expr &&
+{ zstyle -s ":completion:${curcontext}:" substitute expr ||
+  [[ "$curcontext" = expand-word:* ]] && expr=1 } &&
     [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
     exp=( "${(e)exp//\\[ 	
 ]/ }" )
@@ -41,7 +42,8 @@ subd=("$exp[@]")
 
 # Now try globbing.
 
-zstyle -s ":completion:${curcontext}:" glob expr &&
+{ zstyle -s ":completion:${curcontext}:" glob expr ||
+  [[ "$curcontext" = expand-word:* ]] && expr=1 } &&
     [[ "${(e):-\$[$expr]}" -eq 1 ]] &&
     exp=( ${~exp} )
 
@@ -65,28 +67,56 @@ zstyle -s ":completion:${curcontext}:" sort sort
 [[ "$sort" = (yes|true|1|on) ]] && exp=( "${(@o)exp}" )
 
 # If there is only one expansion, add a suitable suffix
-(($#exp == 1)) && suf='' && [[ -d $exp && "$exp[1]" != */ ]] && suf='/'  
+
+if (( $#exp == 1 )); then
+  if [[ -d $exp && "$exp[1]" != */ ]]; then
+    suf=/
+  elif zstyle -T ":completion:${curcontext}:" add-space; then
+    suf=
+  fi
+fi
 
 if [[ -z "$compstate[insert]" ]] ;then
-  _description all-expansions expl 'all expansions' "o:$word"
+  if [[ "$sort" = menu ]]; then
+    _description expansions expl expansions "o:$word"
+  else
+    _description -V expansions expl expansions "o:$word"
+  fi
 
-  compadd "$expl[@]" -UQ -qS "$suf" - "$exp"
+  compadd "$expl[@]" -UQ -qS "$suf" - "$exp[@]"
 else
   _tags all-expansions expansions original
 
-
   if _requested all-expansions; then
     _description all-expansions expl 'all expansions'
     compadd "$expl[@]" -UQ -qS "$suf" - "$exp"
   fi
 
   if [[ $#exp -gt 1 ]] && _requested expansions; then
+    local i normal dir
+
     if [[ "$sort" = menu ]]; then
       _description expansions expl expansions "o:$word"
     else
       _description -V expansions expl expansions "o:$word"
     fi
-    compadd "$expl[@]" -UQ - "$exp[@]"
+    if zstyle -T ":completion:${curcontext}:" add-space; then
+      suf=' '
+    else
+      suf=
+    fi
+    normal=()
+    dir=()
+
+    for i in "$exp[@]"; do
+      if [[ -d "$i" && "$i" != */ ]]; then
+        dir=( "$dir[@]" "$i" )
+      else
+	normal=( "$dir[@]" "$i" )
+      fi
+    done
+    (( $#dir ))    && compadd "$expl[@]" -UQ -qS/ - "$dir[@]"
+    (( $#normal )) && compadd "$expl[@]" -UQ -qS "$suf" - "$normal[@]"
   fi
 
   _requested original expl original && compadd "$expl[@]" -UQ - "$word"