zsh-users
 help / color / mirror / code / Atom feed
* Separate cdpath elements in path-directories completion
@ 2023-02-18 21:10 Sebastian Stark
  2023-02-18 23:03 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Stark @ 2023-02-18 21:10 UTC (permalink / raw)
  To: zsh-users


I have several directories in $cdpath.

In tab completion on cd I have configured "local directory" to show up 
first and then "directory in cdpath". That is almost perfect.

Is it possible to show a separate completion section for each element in 
$cdpath? Looking at the code of _cd I can see that this is happening 
(excerpt):

   tmpcdpath=(${${(@)cdpath:#.}:#$PWD})
   alt=( 'path-directories:directory in cdpath:_path_files -W tmpcdpath -/' )

So I guess it could be done by having my own copy of _cd that changes 
this part of the code.

But perhaps there is a less invasive method I haven't discovered?


Sebastian


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

* Re: Separate cdpath elements in path-directories completion
  2023-02-18 21:10 Separate cdpath elements in path-directories completion Sebastian Stark
@ 2023-02-18 23:03 ` Bart Schaefer
  2023-02-19 10:02   ` Sebastian Stark
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2023-02-18 23:03 UTC (permalink / raw)
  To: zsh-users

On Sat, Feb 18, 2023 at 1:11 PM Sebastian Stark <sstark+zsh@mailbox.org> 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.


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

* Re: Separate cdpath elements in path-directories completion
  2023-02-18 23:03 ` Bart Schaefer
@ 2023-02-19 10:02   ` Sebastian Stark
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Stark @ 2023-02-19 10:02 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

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@mailbox.org> 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


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

end of thread, other threads:[~2023-02-19 10:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 21:10 Separate cdpath elements in path-directories completion Sebastian Stark
2023-02-18 23:03 ` Bart Schaefer
2023-02-19 10:02   ` Sebastian Stark

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