* Re: Separate cdpath elements in path-directories completion [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 0 siblings, 2 replies; 4+ messages in thread From: Oliver Kiddle @ 2023-02-19 16:51 UTC (permalink / raw) To: zsh-workers; +Cc: Sebastian Stark [ 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: 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 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? Oliver ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Separate cdpath elements in path-directories completion 2023-02-19 16:51 ` Separate cdpath elements in path-directories completion Oliver Kiddle @ 2023-02-20 3:54 ` Bart Schaefer 2023-02-21 22:12 ` Sebastian Stark 1 sibling, 0 replies; 4+ messages in thread From: Bart Schaefer @ 2023-02-20 3:54 UTC (permalink / raw) To: zsh-workers On Sun, Feb 19, 2023 at 8:52 AM Oliver Kiddle <opk@zsh.org> wrote: > > 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 -/" ) Strictly speaking unless $elem is always a full path, the argument to -W should be enclosed in parens like: alt+=( "path-directories-$elem:directories in $elem:_path_files -W '($elem)' -/" ) > 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? If just an index it would be hard to e.g. colorize based on location. But I don't have any suggestions for a different transformation. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Separate cdpath elements in path-directories completion 2023-02-19 16:51 ` Separate cdpath elements in path-directories completion Oliver Kiddle 2023-02-20 3:54 ` Bart Schaefer @ 2023-02-21 22:12 ` Sebastian Stark 2023-02-24 12:57 ` Oliver Kiddle 1 sibling, 1 reply; 4+ messages in thread From: Sebastian Stark @ 2023-02-21 22:12 UTC (permalink / raw) To: Oliver Kiddle; +Cc: zsh-workers 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Separate cdpath elements in path-directories completion 2023-02-21 22:12 ` Sebastian Stark @ 2023-02-24 12:57 ` Oliver Kiddle 0 siblings, 0 replies; 4+ messages in thread From: Oliver Kiddle @ 2023-02-24 12:57 UTC (permalink / raw) To: zsh-workers On 21 Feb, Sebastian Stark wrote: > I think a tag should be a) unique and b) easily addressable via zstyle. The index achieves that and will work fine for anyone who doesn't regularly make dynamic changes to their $cdpath. To use your example, I prefer path-directories-1 to path-directories---git but am open to alternatives if someone feels strongly. For now, I'll apply your patch, albeit tweaked to address the point Bart made: Bart wrote: > Strictly speaking unless $elem is always a full path, the argument to > -W should be enclosed in parens like: > alt+=( "path-directories-$elem:directories in $elem:_path_files -W '($elem)' -/" ) I'm getting files from root mixed in if I use _path_files -W '( .. )' Is that intentional or a bug? While the documentation states that it can be an array, full path or paren-enclosed list, it can be a non-array variable or reference to an array element. That works for things like .. appearing in $CDPATH so is what I've used. Thanks Sebastian for updating and contributing the patch. Oliver ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-24 12:58 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [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 ` Separate cdpath elements in path-directories completion Oliver Kiddle 2023-02-20 3:54 ` Bart Schaefer 2023-02-21 22:12 ` Sebastian Stark 2023-02-24 12:57 ` Oliver Kiddle
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).