zsh-workers
 help / color / mirror / code / Atom feed
* Author: Alexey I. Froloff <raorn@altlinux.org>
@ 2008-08-16  7:02 Alexey I. Froloff
  0 siblings, 0 replies; only message in thread
From: Alexey I. Froloff @ 2008-08-16  7:02 UTC (permalink / raw)
  To: zsh workers

    _files: "list-dirs-first" style.
    
    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:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-08-16  7:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-16  7:02 Author: Alexey I. Froloff <raorn@altlinux.org> Alexey I. Froloff

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).