about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-01-04 15:02:25 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-01-04 15:02:25 +0000
commit01d4ad38356395d4cc47d9972b29d5643673df6f (patch)
tree482a7d08628b2fcd04c016a383938604edcdb5e7
parentbf2b2bcce77371871c4e35eda549756c89b62fdc (diff)
downloadzsh-01d4ad38356395d4cc47d9972b29d5643673df6f.tar.gz
zsh-01d4ad38356395d4cc47d9972b29d5643673df6f.tar.xz
zsh-01d4ad38356395d4cc47d9972b29d5643673df6f.zip
zsh-workers/9199
-rw-r--r--Completion/Core/_path_files33
-rw-r--r--Doc/Zsh/compsys.yo12
2 files changed, 44 insertions, 1 deletions
diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files
index 55d0aefa9..415a55acb 100644
--- a/Completion/Core/_path_files
+++ b/Completion/Core/_path_files
@@ -6,7 +6,7 @@
 local linepath realpath donepath prepath testpath exppath
 local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
 local pats haspats=no ignore group expl addpfx addsfx remsfx
-local nm=$compstate[nmatches] menu match matcher mopts atmp
+local nm=$compstate[nmatches] menu match matcher mopts atmp sort
 
 typeset -U prepaths exppaths
 
@@ -111,6 +111,37 @@ if [[ "$sopt" = - ]]; then
   fi
 fi
 
+if zstyle -s ":completion${curcontext}:files" sort tmp1; then
+  case "$tmp1" in
+  *size*)             sort=oL;;
+  *links*)            sort=ol;;
+  *(time|date|modi)*) sort=om;;
+  *access*)           sort=oa;;
+  *(inode|change)*)   sort=oc;;
+  *)                  sort=on;;
+  esac
+  [[ "$tmp1" = *rev* ]] && sort[1]=O
+
+  if [[ "$sort" = on ]]; then
+    sort=''
+  else
+    group=( "${(@)group/#-J/-V}" )
+    expl=( "${(@)expl/#-J/-V}" )
+
+    tmp2=()
+    for tmp1 in "$pats[@]"; do
+      if [[ "$tmp1" = ?*\(\([^\|~]##\)\) ]]; then
+        tmp2=( "$tmp2[@]" "${tmp1[1,-3]}${sort}))" )
+      elif [[ "$tmp1" = ?*\([^\|~]##\) ]]; then
+        tmp2=( "$tmp2[@]" "${tmp1[1,-2]}${sort})" )
+      else
+        tmp2=( "$tmp2[@]" "${tmp1}(${sort})" )
+      fi
+    done
+    pats=( "$tmp2[@]" )
+  fi
+fi
+
 # We get the prefix and the suffix from the line and save the whole
 # original string. Then we see if we will do menucompletion.
 
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 329a07d88..331cc5096 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1101,6 +1101,18 @@ history as possible matches sort these words alphabetically instead of
 keeping them in the order in which they appear in the history (from
 youngest to oldest).
 
+The completion function that generates filenames as possible matches
+uses this style with the tt(files) tag to determine in which order the 
+names should be listed and completed when using menucompletion. The
+value may be one of tt(size) to sort them by the size of the file,
+tt(links) to sort them by the number of links to the file,
+tt(modification) (or tt(time) or tt(date)) to sort them by the last
+modification time, tt(access) to sort them by the last access time, or 
+tt(inode) (or tt(change)) to sort them by the last inode change
+time. Any other value (or not setting this style at all) makes them be 
+sorted alphabetically by name. If the value contains the string
+tt(reverse), sorting is done in decreasing order.
+
 This is also used by the tt(_expand) completer. Here, if it is set to
 `true', the expansions generated will always be sorted. If it is set
 to tt(menu), then the expansions are only sorted when they are offered