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

Re: PATH_DIRS and command completion



On Fri, 06 Jan 2012 18:11:22 +0100
Christian Neukirchen <chneukirchen@xxxxxxxxx> wrote:
> just yesterday I found the PATH_DIRS option and really like the
> behavior:
> 
> Unfortunately, tab command completion doesn't complete the folders in
> $PATH.  Has anyone hacked that in already?

I think this does it, and also completes executables in the folders so
found, but let me know...

Index: Completion/Unix/Type/_path_commands
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_path_commands,v
retrieving revision 1.6
diff -p -u -r1.6 _path_commands
--- Completion/Unix/Type/_path_commands	2 Nov 2008 14:12:30 -0000	1.6
+++ Completion/Unix/Type/_path_commands	7 Jan 2012 20:34:18 -0000
@@ -82,6 +82,18 @@ if [[ -n $need_desc ]]; then
 else
   _wanted commands expl 'external command' compadd "$@" -k commands && ret=0
 fi
+if [[ -o path_dirs ]]; then
+  local -a path_dirs
+  path_dirs=(${^path}/*(/N:t))
+  (( ${#path_dirs} )) &&
+  _wanted path-dirs expl 'directory in path' compadd "$@" -a path_dirs && ret=0
+
+  if [[ $PREFIX$SUFFIX = */* ]]; then
+    # Find command from path, not hashed
+    _wanted commands expl 'external command' _path_files -W path -g '*(*)' &&
+    ret=0
+  fi
+fi
 
 return $ret
 }

-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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