zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Stark <sstark+zsh@mailbox.org>
To: Oliver Kiddle <opk@zsh.org>
Cc: zsh-workers@zsh.org
Subject: Re: Separate cdpath elements in path-directories completion
Date: Tue, 21 Feb 2023 23:12:47 +0100	[thread overview]
Message-ID: <20230221221247.aacrywwb7fmnzmew@singold.localdomain> (raw)
In-Reply-To: <80615-1676825482.916080@qR5n.Nmed.T67B>

Am Sonntag, den 19. Februar 2023 um 18:32 schrieb Oliver Kiddle:
>[ moving to -workers and cc: Sebastian ]
>
>Sebastian Stark wrote:
>> 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.
>
>I realise that you posted this "in case somebody wants that feature
>too" rather than as an explicit contribution but if we include this in
>the distributed _cd, it'd be rather easier to use. For that, there's a
>couple of changes I would suggest:

I wouldn't mind trying to get this in shape for an explicit 
contribution, if I can be of any help with it.

>cd completion otherwise uses the tag "path-directories" for directories
>from $CDPATH. It is always better if you can vary the context but reuse
>an existing style name. In this case, the separate-sections style would
>be appropriate. This would then need to be:
>
>  zstyle ':completion:*:path-directories' separate-sections true

This makes much more sense indeed. And helped me understand zstyle 
better.

>Also, I would probably suggest expanding the description to "directory
>in $elem" instead of just "$elem" as here:
>
>> +        alt+=( "path-directories-$elem:$elem:_path_files -W $elem -/" )
>> +      done
>> +    else
>> +      (( $#tmpcdpath )) &&
>> +        alt=( 'path-directories:directory in cdpath:_path_files -W tmpcdpath -/' )
>
>I'm also unsure about including $elem in the tag. It will probably work
>fine but doesn't exactly conform with usual tag naming conventions.
>Perhaps just an index for the position in the cdpath array. Does anyone
>else have an opinion on that?

I think a tag should be a) unique and b) easily addressable via zstyle.

The index in $CDPATH would satisfy these requirements. Although if we 
had some normalized form of the directory here, e. g. by replacing all 
non-alphanumeric characters with '-', one could address an individual 
path by its name instead of its index, making my zstyling immune to the 
order in $CDPATH. For example for cdpath=(~/git /some/other/dir):

   zstyle ':completion:*:path-directories-1' format "Git Repositories:"

as opposed to:

   zstyle ':completion:*:path-directories---git' format "Git Repositories:"

The latter being slightly opaque syntax unfortunately.

Updated patch using the index and the other suggestions added:

--- /usr/share/zsh/functions/Completion/Zsh/_cd	2023-02-08 23:22:07.000000000 +0100
+++ .zfunc/_cd	2023-02-21 22:45:35.731260952 +0100
@@ -70,8 +70,15 @@

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

-    (( $#tmpcdpath )) &&
-      alt=( 'path-directories:directory in cdpath:_path_files -W tmpcdpath -/' )
+    if zstyle -t ":completion:${curcontext}:path-directories" separate-sections; then
+      local elem
+      for elem in $tmpcdpath; do
+        alt+=( "path-directories-${tmpcdpath[(ie)$elem]}:directory in $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



  parent reply	other threads:[~2023-02-21 22:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230218211046.vj3p4k7y6uraytpo@singold.localdomain>
     [not found] ` <CAH+w=7bhjyXVgMb7esyg-1n0SbBAZogUrCVg34wFB64z3aUimg@mail.gmail.com>
     [not found]   ` <20230219100217.f2mcniygwgbtxvwf@singold.localdomain>
2023-02-19 16:51     ` Oliver Kiddle
2023-02-20  3:54       ` Bart Schaefer
2023-02-21 22:12       ` Sebastian Stark [this message]
2023-02-24 12:57         ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230221221247.aacrywwb7fmnzmew@singold.localdomain \
    --to=sstark+zsh@mailbox.org \
    --cc=opk@zsh.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).