Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: compctl tab order by modification date
- X-seq: zsh-workers 9199
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: compctl tab order by modification date
- Date: Tue, 4 Jan 2000 14:45:25 +0100 (MET)
- Cc: Eric Smith <eric@xxxxxxxxxxxx>
- In-reply-to: Eric Smith's message of Tue, 28 Dec 1999 00:27:43 +0200
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
[ List changed to zsh-workers and CC'ed to Eric. ]
Eric Smith wrote:
> Hi
>
> I would like to tab through files in order of their modification date, most
> recent first. How could I set completion control to do this?
Currently there is no way to do that. However, the patch to allow this
in the new completion system is quite simple -- see below. It adds the
style `sort' for the `files' tag, so that:
zstyle ':completion:*:files' sort time
gives what you wanted.
With `compctl' I don't see a nice-enough solution (a completion
function calling `ls -t' is not `nice', I think).
I don't know if this patch is interesting enough to be included in the
distribution, though.
Bye
Sven
diff -ru ../z.old/Completion/Core/_path_files Completion/Core/_path_files
--- ../z.old/Completion/Core/_path_files Tue Jan 4 14:06:00 2000
+++ Completion/Core/_path_files Tue Jan 4 14:42:03 2000
@@ -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
@@ -99,6 +99,37 @@
pats=('*')
else
unset sopt
+ 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
diff -ru ../z.old/Doc/Zsh/compsys.yo Doc/Zsh/compsys.yo
--- ../z.old/Doc/Zsh/compsys.yo Tue Jan 4 10:15:50 2000
+++ Doc/Zsh/compsys.yo Tue Jan 4 14:38:25 2000
@@ -1093,6 +1093,18 @@
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
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author