Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Author: Alexey I. Froloff <raorn@xxxxxxxxxxxx>



    _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@xxxxxxxxxxxx>
---
 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:



Messages sorted by: Reverse Date, Date, Thread, Author