zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _files: "list-dirs-first" style.
@ 2008-08-16  7:06 Alexey I. Froloff
  2008-08-18  9:57 ` Alexey I. Froloff
  2008-08-21 15:54 ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Alexey I. Froloff @ 2008-08-16  7:06 UTC (permalink / raw)
  To: zsh workers; +Cc: Alexey I. Froloff

When this style set to "true", directories are shown before
files.  Also instead of "all-files" tag it offers
"other-files" bceause directories are excluded from file
list.  Screenshot:

user@host /usr/libexec $ ls <Tab>
---- directories ----
awk/                    ConsoleKit/
dbus-1/                 evolution-data-server/
gcc/                    gnupg/
gvfs/                   hal/
hasher-priv/            PolicyKit/
postfix/                sudo/
X11/                    xscreensaver/
---- files ----
ck-collect-session-info*

This can also be done by setting "file-patterns" style to
'*(-/):directories:directories %p(^-/):other-files'
("directories" tag description is required to split groups),
but completion for "zmodload" command doesn't offer modules.

Another possible solution does not work either:

zstyle ':completion:*' file-patterns '*(-/):directories:directories %p:other-files'
zstyle ':completion:*:other-files' ignored-patterns '*(-/)'

"ignored-patterns" seems to be ignored by _path_files...

Signed-off-by: Alexey I. Froloff <raorn@altlinux.org>
---
 Completion/Unix/Type/_files    |   17 +++++++++++++++++
 Completion/Zsh/Command/_zstyle |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/Completion/Unix/Type/_files b/Completion/Unix/Type/_files
index a3545cb..4615a60 100644
--- a/Completion/Unix/Type/_files
+++ b/Completion/Unix/Type/_files
@@ -39,6 +39,23 @@ if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
       pats=( "$pats[@]" " ${i}:files " )
     fi
   done
+elif zstyle -t ":completion:${curcontext}:" list-dirs-first; then
+  if [[ "$type" = *g* ]]; then
+
+    # add `^-/' after `#q' glob qualifier if not there already
+    if [[ "$glob" = (#b)(*\(\#q)(*\)) ]]; then
+      [[ $match[2] != \^-/* ]] &&
+      glob="${match[1]}^-/,${match[2]}"
+    else
+      glob="$glob(#q^-/)"
+    fi
+
+    pats=( " *(-/):directories:directories ${glob//:/\\:}:globbed-files" )
+  elif [[ "$type" = */* ]] then
+    pats=( '*(-/):directories ' '*:all-files ' )
+  else
+    pats=( '*(-/):directories:directories *(^-/):other-files ' )
+  fi
 else
   if [[ "$type" = *g* ]]; then
 
diff --git a/Completion/Zsh/Command/_zstyle b/Completion/Zsh/Command/_zstyle
index 2bf2709..a181a7b 100644
--- a/Completion/Zsh/Command/_zstyle
+++ b/Completion/Zsh/Command/_zstyle
@@ -68,6 +68,7 @@ styles=(
   last-prompt		 c:bool
   list			 c:listwhen
   list-colors		 c:
+  list-dirs-first	 c:bool
   list-grouped		 c:bool
   list-packed		 c:bool
   list-prompt            c:
-- 
1.5.6.5.GIT


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-08-22 20:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-16  7:06 [PATCH] _files: "list-dirs-first" style Alexey I. Froloff
2008-08-18  9:57 ` Alexey I. Froloff
2008-08-21 15:54 ` Peter Stephenson
2008-08-22 20:04   ` Richard Hartmann

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).