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

Re: Dynamic named directories and completion



On 2/23/18 3:01 AM, Vincent Bernat wrote:
  ❦ 22 février 2018 17:54 -0500, Scott Frazer <frazer.scott@xxxxxxxxx> :

zsh_directory_name ()
{
     emulate -L zsh
     setopt extendedglob
     local -a seg;
     seg=(${(s:/:)PWD%/*})
     if [[ $1 = n ]]; then
         typeset -ga reply
         reply=( /${(j:/:)seg[1,(I)$2]} )
     elif [[ $1 = c ]]; then
         local expl
         _wanted values expl 'parent dirs' compadd -S\] -a seg
     else
         return 1
     fi
     return 0
}

Suppose I am in directory /aaa/bbb/ccc/ddd/eee and want to go up to directory
ccc and then down into another directory.  If I do:

cd ~[c<TAB>

it correctly completes to:

cd ~[ccc]

If I hit enter at this point I go to /aaa/bbb/ccc.  So far so good.  If I
try to start completion, like so:

cd ~[ccc]/<TAB>

zsh doesn't give me options for directories under ccc, it thinks '/' is
the command I'm trying to complete.  Is there a way to make this work?

I don't see anything wrong in your code and for me, it works as you
expect (zsh 5.4.2). Does "echo ~[ccc]" returns the right value?


Yes, "echo ~[ccc]" works correctly.  I'm using zsh 5.3 so maybe there is some
difference there.  Perhaps there is some difference in options/modules/etc.  If
I cut my .zshrc down to a minimum:

autoload -Uz compinit
compinit

zstyle ':completion:*' verbose yes
zstyle ':completion:*' menu select=2
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' squeeze-slashes true

zstyle ':completion:*:descriptions' format "%UCompleting %d:%u"
zstyle ':completion:*:warnings' format "No matches for: %d"

(with the above zsh_directory_name() too of course), plain ~[whatever] works
but ~[whatever]/ will not complete paths.  Do you have anything non-standard
in your completion?

Scott




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