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

Re: Separate cdpath elements in path-directories completion



Am Sonntag, den 19. Februar 2023 um 00:05 schrieb Bart Schaefer:
On Sat, Feb 18, 2023 at 1:11 PM Sebastian Stark <sstark+zsh@xxxxxxxxxxx> wrote:

Is it possible to show a separate completion section for each element in
$cdpath?

You would have to arrange that each directory's name becomes a tag
(the "path-directories:" part in the alt= assignment) and call
"_path_files -W" separately for each directory.  There's no existing
shortcut for this.

Thanks for showing me the right direction. I ended up with the following, in case somebody wants that feature too. I can control the behaviour by adding

  "zstyle ':completion:*:directories' cdpath-sections true"

to my config.

--- /usr/share/zsh/functions/Completion/Zsh/_cd	2023-02-08 23:22:07.000000000 +0100
+++ .zfunc/_cd	2023-02-19 10:51:50.263265022 +0100
@@ -70,8 +70,15 @@

     tmpcdpath=(${${(@)cdpath:#.}:#$PWD})

-    (( $#tmpcdpath )) &&
-      alt=( 'path-directories:directory in cdpath:_path_files -W tmpcdpath -/' )
+    if zstyle -t ":completion:${curcontext}:directories" cdpath-sections; then
+      local elem
+      for elem in $tmpcdpath; do
+        alt+=( "path-directories-$elem:$elem:_path_files -W $elem -/" )
+      done
+    else
+      (( $#tmpcdpath )) &&
+        alt=( 'path-directories:directory in cdpath:_path_files -W tmpcdpath -/' )
+    fi

     # With cdablevars, we can complete foo as if ~foo/
     if [[ -o cdablevars && -n "$PREFIX" && "$PREFIX" != <-> ]]; then


Sebastian




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