* Dynamic named directories and completion @ 2018-02-22 22:54 Scott Frazer 2018-02-23 0:29 ` [RFC PATCH] _path_files: teach zsh_directory_name Takeshi Banse 2018-02-23 8:01 ` Dynamic named directories and completion Vincent Bernat 0 siblings, 2 replies; 19+ messages in thread From: Scott Frazer @ 2018-02-22 22:54 UTC (permalink / raw) To: zsh-users I'm trying to use dynamic named directories and have subsequent completion work. Here is my (perhaps naive) attempt: 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? Thanks, Scott ^ permalink raw reply [flat|nested] 19+ messages in thread
* [RFC PATCH] _path_files: teach zsh_directory_name 2018-02-22 22:54 Dynamic named directories and completion Scott Frazer @ 2018-02-23 0:29 ` Takeshi Banse 2018-02-23 1:19 ` _path_files: fix copy paste error Takeshi Banse 2018-02-23 1:30 ` _path_files: fix copy paste error (2/2) Takeshi Banse 2018-02-23 8:01 ` Dynamic named directories and completion Vincent Bernat 1 sibling, 2 replies; 19+ messages in thread From: Takeshi Banse @ 2018-02-23 0:29 UTC (permalink / raw) To: zsh-users; +Cc: zsh-workers, Takeshi Banse Signed-off-by: Takeshi Banse <thb@laafc.net> --- Hi, I want this feature, too. It is necessary to tweak _path_files function as far as I can tell. So, I wrote a patch. To zsh-workers: This `elif` clause could be merged with the following `elif` clause because it starts with \~, too. But it may break something, so I did prepend the separate `elif` clause for \~\[*. Completion/Unix/Type/_path_files | 70 ++++++++++++++++++++++++++++++++++++++++ Test/Y01completion.ztst | 30 +++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files index 9fa6ae9fc..8fbc21ffa 100644 --- a/Completion/Unix/Type/_path_files +++ b/Completion/Unix/Type/_path_files @@ -274,6 +274,76 @@ if [[ "$pre" = [^][*?#^\|\<\>\\]#(\`[^\`]#\`|\$)*/* && "$compstate[quote]" != \' orig="${orig[1,(in:i:)/][1,-2]}" donepath= prepaths=( '' ) +elif [[ "$pre" = \~\[* && "$compstate[quote]" = (|\`) ]]; then + (($+functions[zsh_directory_name] || $+zsh_directory_name_functions)) && + () { + # It begins with `~[', so the characters from `$pre[3]' to before the + # first `]' represent the dynamic directory name. Otherwise, it may fall + # through to the following elif/else clauses. + + local name= + () { + local -i i=3 n=$#pre sq=0 dq=0 + local c= + while ((i<=n)); do + c=$pre[i++] + case $c in + (\') + if ((sq)); then + ((sq=0)) + elif ((dq==0)); then + ((sq=1)) + fi + ;; + (\") + if [[ "$name[-1]" != '\' ]]; then + if ((dq)); then + ((dq=0)) + elif ((sq==0)); then + ((dq=1)) + fi + fi + ;; + (\;) ;& + (]) + repeat 1; do + ((sq || dq)) && break + [[ "$name[-1]" == '\' ]] && break + [[ "$c" == ';' ]] && return 1 + return 0 + done + ;; + esac + name+="$c" + done + return 1 + } && + () { + local -a reply + local -i ret=1 + if (($+functions[zsh_directory_name])); then + zsh_directory_name n "$name" + ret=$? + fi + if ((ret != 0)); then + local func= + for func in "${zsh_directory_name_functions[@]-}"; do + "$func" n "$name" + ret=$? + ((ret == 0)) && break + done + fi + if ((ret == 0)); then + realpath="$reply[1]/" + linepath="$pre[1,$#name+2+1]/" + fi + return ret + } + } then + pre="${pre#${linepath}}" + orig="${orig#${linepath}}" + donepath= + prepaths=( '' ) elif [[ "$pre[1]" = \~ && "$compstate[quote]" = (|\`) ]]; then # It begins with `~', so remember anything before the first slash to be able diff --git a/Test/Y01completion.ztst b/Test/Y01completion.ztst index b1c0e40e5..cbfbb75d7 100644 --- a/Test/Y01completion.ztst +++ b/Test/Y01completion.ztst @@ -36,6 +36,36 @@ >line: {: dir1/}{} >line: {: dir2/}{} + comptesteval 'zsh_directory_name () { + case "$1" in + (d) + return 1 + ;; + (n) + reply=("$2") + ;; + (c) + local expl + _wanted dynamic-dirs expl dynamic compadd -S\] -Q -- ./ + ;; + esac + }' + comptest $': ~[\t/\t\t\t\t\t\t\t' +0:tilde with zsh_directory_name +>line: {: ~[./]}{} +>line: {: ~[./]/}{} +>DESCRIPTION:{file} +>DI:{dir1} +>DI:{dir2} +>FI:{file1} +>FI:{file2} +>line: {: ~[./]/dir1/}{} +>line: {: ~[./]/dir2/}{} +>line: {: ~[./]/file1}{} +>line: {: ~[./]/file2}{} +>line: {: ~[./]/dir1/}{} +>line: {: ~[./]/dir2/}{} + comptesteval '_users () { compadd user1 user2 }' comptest $': ~\t\t\t\t\t' 0:tilde -- 2.16.1 ^ permalink raw reply [flat|nested] 19+ messages in thread
* _path_files: fix copy paste error 2018-02-23 0:29 ` [RFC PATCH] _path_files: teach zsh_directory_name Takeshi Banse @ 2018-02-23 1:19 ` Takeshi Banse 2018-02-23 1:30 ` _path_files: fix copy paste error (2/2) Takeshi Banse 1 sibling, 0 replies; 19+ messages in thread From: Takeshi Banse @ 2018-02-23 1:19 UTC (permalink / raw) To: zsh-users; +Cc: zsh-workers, Takeshi Banse Signed-off-by: Takeshi Banse <thb@laafc.net> --- I'm very sorry! I fixed the copy paste error in the previous patch. Completion/Unix/Type/_path_files | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files index 8fbc21ffa..6a869defa 100644 --- a/Completion/Unix/Type/_path_files +++ b/Completion/Unix/Type/_path_files @@ -274,7 +274,7 @@ if [[ "$pre" = [^][*?#^\|\<\>\\]#(\`[^\`]#\`|\$)*/* && "$compstate[quote]" != \' orig="${orig[1,(in:i:)/][1,-2]}" donepath= prepaths=( '' ) -elif [[ "$pre" = \~\[* && "$compstate[quote]" = (|\`) ]]; then +elif [[ "$pre" = \~\[* && "$compstate[quote]" = (|\`) ]] && (($+functions[zsh_directory_name] || $+zsh_directory_name_functions)) && () { # It begins with `~[', so the characters from `$pre[3]' to before the -- 2.16.1 ^ permalink raw reply [flat|nested] 19+ messages in thread
* _path_files: fix copy paste error (2/2) 2018-02-23 0:29 ` [RFC PATCH] _path_files: teach zsh_directory_name Takeshi Banse 2018-02-23 1:19 ` _path_files: fix copy paste error Takeshi Banse @ 2018-02-23 1:30 ` Takeshi Banse 1 sibling, 0 replies; 19+ messages in thread From: Takeshi Banse @ 2018-02-23 1:30 UTC (permalink / raw) To: zsh-users; +Cc: zsh-workers, Takeshi Banse Signed-off-by: Takeshi Banse <thb@laafc.net> --- I'm sorry! This fixes the copy paste error eventually. Completion/Unix/Type/_path_files | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Completion/Unix/Type/_path_files b/Completion/Unix/Type/_path_files index 6a869defa..9c55df418 100644 --- a/Completion/Unix/Type/_path_files +++ b/Completion/Unix/Type/_path_files @@ -339,7 +339,7 @@ elif [[ "$pre" = \~\[* && "$compstate[quote]" = (|\`) ]] && fi return ret } - } then + }; then pre="${pre#${linepath}}" orig="${orig#${linepath}}" donepath= -- 2.16.1 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-22 22:54 Dynamic named directories and completion Scott Frazer 2018-02-23 0:29 ` [RFC PATCH] _path_files: teach zsh_directory_name Takeshi Banse @ 2018-02-23 8:01 ` Vincent Bernat 2018-02-23 14:41 ` Scott Frazer 2018-02-23 14:42 ` Scott Frazer 1 sibling, 2 replies; 19+ messages in thread From: Vincent Bernat @ 2018-02-23 8:01 UTC (permalink / raw) To: Scott Frazer; +Cc: zsh-users ❦ 22 février 2018 17:54 -0500, Scott Frazer <frazer.scott@gmail.com> : > 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? -- This was the most unkindest cut of all. -- William Shakespeare, "Julius Caesar" ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-23 8:01 ` Dynamic named directories and completion Vincent Bernat @ 2018-02-23 14:41 ` Scott Frazer 2018-02-23 15:02 ` Takeshi Banse 2018-02-23 14:42 ` Scott Frazer 1 sibling, 1 reply; 19+ messages in thread From: Scott Frazer @ 2018-02-23 14:41 UTC (permalink / raw) To: zsh-users; +Cc: zsh-users On 2/23/18 3:01 AM, Vincent Bernat wrote: > ❦ 22 février 2018 17:54 -0500, Scott Frazer <frazer.scott@gmail.com> : > >> 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 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-23 14:41 ` Scott Frazer @ 2018-02-23 15:02 ` Takeshi Banse 0 siblings, 0 replies; 19+ messages in thread From: Takeshi Banse @ 2018-02-23 15:02 UTC (permalink / raw) To: zsh-users Hi, * Scott Frazer <frazer.scott@gmail.com> [2018-02-23 23:41]: > (with the above zsh_directory_name() too of course), plain ~[whatever] works > but ~[whatever]/ will not complete paths. I would like to do this feature, too. It is necessary to tweak `_path_files` function as far as I can tell. Here are the patch: http://www.zsh.org/mla/users/2018/msg00119.html Or, http://www.zsh.org/mla/workers/2018/msg00198.html I sent these mails with different subjects, sorry for the inconvenience! ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-23 8:01 ` Dynamic named directories and completion Vincent Bernat 2018-02-23 14:41 ` Scott Frazer @ 2018-02-23 14:42 ` Scott Frazer 2018-02-24 19:34 ` Peter Stephenson 1 sibling, 1 reply; 19+ messages in thread From: Scott Frazer @ 2018-02-23 14:42 UTC (permalink / raw) To: zsh-users On 2/23/18 3:01 AM, Vincent Bernat wrote: > ❦ 22 février 2018 17:54 -0500, Scott Frazer <frazer.scott@gmail.com> : > >> 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 ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-23 14:42 ` Scott Frazer @ 2018-02-24 19:34 ` Peter Stephenson 2018-02-24 19:49 ` Mikael Magnusson 2018-02-26 13:53 ` Scott Frazer 0 siblings, 2 replies; 19+ messages in thread From: Peter Stephenson @ 2018-02-24 19:34 UTC (permalink / raw) To: zsh-users On Fri, 23 Feb 2018 09:42:37 -0500 Scott Frazer <frazer.scott@gmail.com> wrote: > >> 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: There's something screwy here, certainly. I don't think it should be necessary to modify _path_files in 5.3, though, there are certainly cases where you get the right answer, and I think the logic that currently handles ~ at the start should do the right thing here. I've a theory it's down to the completion widget in use, i.e. how completion gets started up. If instead of hitting tab, you type <Esc>x complete-word<Enter> --- or instead bind that widget, bindkey '^i' complete-word and then use tab --- does it start working? The default is expand-or-complete, and I believe the expand bit is nixing the completion in this case. (Except we don't really have the word "nix" this side of the Atlantic, so I may be talking nonsense, but it sounded good.) pws ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-24 19:34 ` Peter Stephenson @ 2018-02-24 19:49 ` Mikael Magnusson 2018-02-24 20:12 ` Peter Stephenson 2018-02-26 13:53 ` Scott Frazer 1 sibling, 1 reply; 19+ messages in thread From: Mikael Magnusson @ 2018-02-24 19:49 UTC (permalink / raw) To: Peter Stephenson; +Cc: Zsh Users On Sat, Feb 24, 2018 at 8:34 PM, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote: > On Fri, 23 Feb 2018 09:42:37 -0500 > Scott Frazer <frazer.scott@gmail.com> wrote: >> >> 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: > > There's something screwy here, certainly. I don't think it should be > necessary to modify _path_files in 5.3, though, there are certainly > cases where you get the right answer, and I think the logic that currently > handles ~ at the start should do the right thing here. > > I've a theory it's down to the completion widget in use, i.e. how > completion gets started up. If instead of hitting tab, you type <Esc>x > complete-word<Enter> --- or instead bind that widget, > > bindkey '^i' complete-word > > and then use tab --- does it start working? The default is > expand-or-complete, and I believe the expand bit is nixing the > completion in this case. (Except we don't really have the word "nix" > this side of the Atlantic, so I may be talking nonsense, but it sounded > good.) I have some patches I was working on related to this, but I assume there was still some problem, or I would have committed them... There's two patches in this thread, http://www.zsh.org/mla/workers/2015/msg01439.html and then I think I never sent the third one, diff --git a/Completion/Unix/Type/_files b/Completion/Unix/Type/_files index 2b0c5580a5..067f68d9d9 100644 --- a/Completion/Unix/Type/_files +++ b/Completion/Unix/Type/_files @@ -103,7 +103,7 @@ for def in "$pats[@]"; do if [[ -n "$end" ]]; then if _path_files -g "$pat" "$opts[@]" "$expl[@]"; then ret=0 - elif [[ $PREFIX$SUFFIX != */* ]] && zstyle -a ":completion:${curcontext}:$tag" recursive-files rfiles; then + elif [[ ${${:-$PREFIX$SUFFIX}#\~\[[^]]#]} != */* ]] && zstyle -a ":completion:${curcontext}:$tag" recursive-files rfiles; then local subtree for rfile in $rfiles; do if [[ $PWD/ = ${~rfile} ]]; then -- Mikael Magnusson ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-24 19:49 ` Mikael Magnusson @ 2018-02-24 20:12 ` Peter Stephenson 2018-02-26 14:31 ` Scott Frazer 0 siblings, 1 reply; 19+ messages in thread From: Peter Stephenson @ 2018-02-24 20:12 UTC (permalink / raw) To: Zsh Users On Sat, 24 Feb 2018 20:49:14 +0100 Mikael Magnusson <mikachu@gmail.com> wrote: > I have some patches I was working on related to this, but I assume > there was still some problem, or I would have committed them... > There's two patches in this thread, > http://www.zsh.org/mla/workers/2015/msg01439.html and then I think I > never sent the third one, This is all quite complicated so I can well believe it's useful; I don't think it fixes the behaviour I was seeing (but I may be getting confused). On the same theme, I think the following is useful for those of us using the _expand completer, which may well have nothing whatsoever to do with the original problem. pws diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand index a6e30e8..ee3681b 100644 --- a/Completion/Base/Completer/_expand +++ b/Completion/Base/Completer/_expand @@ -43,7 +43,8 @@ zstyle -s ":completion:${curcontext}:" accept-exact tmp || if [[ "$tmp" != (yes|true|on|1) ]]; then { [[ "$word" = \~(|[-+]) || - ( "$word" = \~[-+][1-9]## && $word[3,-1] -le $#dirstack ) ]] && return 1 } + ( "$word" = \~[-+][1-9]## && $word[3,-1] -le $#dirstack ) || + $word = \~\[*\]/* ]] && return 1 } { [[ ( "$word" = \~* && ${#userdirs[(I)${word[2,-1]}*]}+${#nameddirs[(I)${word[2,-1]}*]} -gt 1 ) || ( "$word" = *\$[a-zA-Z0-9_]## && ${#parameters[(I)${word##*\$}*]} -ne 1 ) ]] && continue=1 } ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-24 20:12 ` Peter Stephenson @ 2018-02-26 14:31 ` Scott Frazer 0 siblings, 0 replies; 19+ messages in thread From: Scott Frazer @ 2018-02-26 14:31 UTC (permalink / raw) To: zsh-users On 2/24/18 3:12 PM, Peter Stephenson wrote: > On Sat, 24 Feb 2018 20:49:14 +0100 > Mikael Magnusson <mikachu@gmail.com> wrote: >> I have some patches I was working on related to this, but I assume >> there was still some problem, or I would have committed them... >> There's two patches in this thread, >> http://www.zsh.org/mla/workers/2015/msg01439.html and then I think I >> never sent the third one, > > This is all quite complicated so I can well believe it's useful; I don't > think it fixes the behaviour I was seeing (but I may be getting > confused). > > On the same theme, I think the following is useful for those of us > using the _expand completer, which may well have nothing whatsoever to > do with the original problem. > > pws > > diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand > index a6e30e8..ee3681b 100644 > --- a/Completion/Base/Completer/_expand > +++ b/Completion/Base/Completer/_expand > @@ -43,7 +43,8 @@ zstyle -s ":completion:${curcontext}:" accept-exact tmp || > > if [[ "$tmp" != (yes|true|on|1) ]]; then > { [[ "$word" = \~(|[-+]) || > - ( "$word" = \~[-+][1-9]## && $word[3,-1] -le $#dirstack ) ]] && return 1 } > + ( "$word" = \~[-+][1-9]## && $word[3,-1] -le $#dirstack ) || > + $word = \~\[*\]/* ]] && return 1 } > { [[ ( "$word" = \~* && ${#userdirs[(I)${word[2,-1]}*]}+${#nameddirs[(I)${word[2,-1]}*]} -gt 1 ) || > ( "$word" = *\$[a-zA-Z0-9_]## && > ${#parameters[(I)${word##*\$}*]} -ne 1 ) ]] && continue=1 } > Just this patch does not fix the completion issue (I even upgraded to 5.4.2 just to be sure). Since M-x complete-word does work, I may try looking at expand-or-complete to see if I can figure out what is happening. I'm no zsh expert though, so I will likely need help not breaking something else. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-24 19:34 ` Peter Stephenson 2018-02-24 19:49 ` Mikael Magnusson @ 2018-02-26 13:53 ` Scott Frazer 2018-02-26 14:47 ` Peter Stephenson 1 sibling, 1 reply; 19+ messages in thread From: Scott Frazer @ 2018-02-26 13:53 UTC (permalink / raw) To: zsh-users On 2/24/18 2:34 PM, Peter Stephenson wrote: > On Fri, 23 Feb 2018 09:42:37 -0500 > Scott Frazer <frazer.scott@gmail.com> wrote: >>>> 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: > > There's something screwy here, certainly. I don't think it should be > necessary to modify _path_files in 5.3, though, there are certainly > cases where you get the right answer, and I think the logic that currently > handles ~ at the start should do the right thing here. > > I've a theory it's down to the completion widget in use, i.e. how > completion gets started up. If instead of hitting tab, you type <Esc>x > complete-word<Enter> --- or instead bind that widget, > > bindkey '^i' complete-word > > and then use tab --- does it start working? The default is > expand-or-complete, and I believe the expand bit is nixing the > completion in this case. (Except we don't really have the word "nix" > this side of the Atlantic, so I may be talking nonsense, but it sounded > good.) > > pws > Yes, M-x complete-word does indeed work! I still need to try some of the patches from later in this thread ... Scott ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-26 13:53 ` Scott Frazer @ 2018-02-26 14:47 ` Peter Stephenson 2018-02-26 16:44 ` Scott Frazer 2018-02-26 17:49 ` Mikael Magnusson 0 siblings, 2 replies; 19+ messages in thread From: Peter Stephenson @ 2018-02-26 14:47 UTC (permalink / raw) To: zsh-users On Mon, 26 Feb 2018 08:53:00 -0500 Scott Frazer <frazer.scott@gmail.com> wrote: > Yes, M-x complete-word does indeed work! I still need to try some of the > patches from later in this thread ... Glad it's not totally shrouded in obscurity... Would generally recommend the combination of complete-word as binding for tab + use of the expand completer (which I fixed somewhere else in this thread but am still to commit) as this is much more configurable. To turn it on you'd do something like zstyle ':completion:*' completer _expand _complete _ignored bindkey '^i' complete-word but there are many more exotic possibilities. I'll have a look at expand-or-complete word, too. (Ideally, in fact, whether or not we expand ~[whatever] needs configuring --- because this is dynamic completion you might decide to expand it to freeze the path for future use. I'll look at that if I get the chance. This is the sort of reason for using the expand completer I'm talking about.) pws ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-26 14:47 ` Peter Stephenson @ 2018-02-26 16:44 ` Scott Frazer 2018-02-26 20:08 ` Peter Stephenson 2018-02-26 17:49 ` Mikael Magnusson 1 sibling, 1 reply; 19+ messages in thread From: Scott Frazer @ 2018-02-26 16:44 UTC (permalink / raw) To: zsh-users On 2/26/18 9:47 AM, Peter Stephenson wrote: > On Mon, 26 Feb 2018 08:53:00 -0500 > Scott Frazer <frazer.scott@gmail.com> wrote: >> Yes, M-x complete-word does indeed work! I still need to try some of the >> patches from later in this thread ... > > Glad it's not totally shrouded in obscurity... > > Would generally recommend the combination of complete-word as binding > for tab + use of the expand completer (which I fixed somewhere else in > this thread but am still to commit) as this is much more configurable. > > To turn it on you'd do something like > > zstyle ':completion:*' completer _expand _complete _ignored > bindkey '^i' complete-word > > but there are many more exotic possibilities. > > I'll have a look at expand-or-complete word, too. > > (Ideally, in fact, whether or not we expand ~[whatever] needs > configuring --- because this is dynamic completion you might decide to > expand it to freeze the path for future use. I'll look at that if I get > the chance. This is the sort of reason for using the expand completer > I'm talking about.) > > pws > This plus the small patch you sent earlier for _expand works, thanks! I feel like expand-or-complete should work too, but as long as the _expand patch makes it into the final code I'm happy. Thanks again, Scott ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-26 16:44 ` Scott Frazer @ 2018-02-26 20:08 ` Peter Stephenson 2018-02-26 21:22 ` Peter Stephenson 0 siblings, 1 reply; 19+ messages in thread From: Peter Stephenson @ 2018-02-26 20:08 UTC (permalink / raw) To: zsh-users On Mon, 26 Feb 2018 11:44:14 -0500 Scott Frazer <frazer.scott@gmail.com> wrote: > This plus the small patch you sent earlier for _expand works, thanks! I've pushed that as is. Whether or not tilde forms are expanded are already configurable --- setting the accept-exact style in the completer's context would control this. (Off topic, but I'm not 100% convinced that the REC_EXACT shell option should have that effect in this completer, as it currently does, since it's a rather gross and uncontrllable setting that wasn't really intended for expansion. But I think all its uses are usurped by the accept-exact style in the completion system anyway, so probably no big deal.) > I feel like expand-or-complete should work too, but as long as the > _expand patch makes it into the final code I'm happy. Yes, me too, particularly now Mikael has pointed out ^X*: I'll look at this separately. pws ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-26 20:08 ` Peter Stephenson @ 2018-02-26 21:22 ` Peter Stephenson 0 siblings, 0 replies; 19+ messages in thread From: Peter Stephenson @ 2018-02-26 21:22 UTC (permalink / raw) To: zsh-users On Mon, 26 Feb 2018 20:08:21 +0000 Peter Stephenson <p.w.stephenson@ntlworld.com> wrote: > > I feel like expand-or-complete should work too, but as long as the > > _expand patch makes it into the final code I'm happy. > > Yes, me too, particularly now Mikael has pointed out ^X*: I'll look > at this separately. I think this works. What was happening was as a last search for something to expand the code looked wildcards, and the square brackets triggered that. pws diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index caeef76..22c3812 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -456,6 +456,7 @@ checkparams(char *p) static int cmphaswilds(char *str) { + char *ptr; if ((*str == Inbrack || *str == Outbrack) && !str[1]) return 0; @@ -465,6 +466,14 @@ cmphaswilds(char *str) if (str[0] == '%' && str[1] ==Quest) str += 2; + /* + * In ~[foo], the square brackets are not wild cards. + * This test matches the master one in filesubstr(). + */ + if (*str == Tilde && str[1] == Inbrack && + (ptr = strchr(str+2, Outbrack))) + str = ptr + 1; + for (; *str;) { if (*str == String || *str == Qstring) { /* A parameter expression. */ ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-26 14:47 ` Peter Stephenson 2018-02-26 16:44 ` Scott Frazer @ 2018-02-26 17:49 ` Mikael Magnusson 2018-02-26 17:55 ` Peter Stephenson 1 sibling, 1 reply; 19+ messages in thread From: Mikael Magnusson @ 2018-02-26 17:49 UTC (permalink / raw) To: Peter Stephenson; +Cc: Zsh Users On Mon, Feb 26, 2018 at 3:47 PM, Peter Stephenson <p.stephenson@samsung.com> wrote: > On Mon, 26 Feb 2018 08:53:00 -0500 > Scott Frazer <frazer.scott@gmail.com> wrote: >> Yes, M-x complete-word does indeed work! I still need to try some of the >> patches from later in this thread ... > > Glad it's not totally shrouded in obscurity... > > Would generally recommend the combination of complete-word as binding > for tab + use of the expand completer (which I fixed somewhere else in > this thread but am still to commit) as this is much more configurable. > > To turn it on you'd do something like > > zstyle ':completion:*' completer _expand _complete _ignored > bindkey '^i' complete-word > > but there are many more exotic possibilities. > > I'll have a look at expand-or-complete word, too. > > (Ideally, in fact, whether or not we expand ~[whatever] needs > configuring --- because this is dynamic completion you might decide to > expand it to freeze the path for future use. I'll look at that if I get > the chance. This is the sort of reason for using the expand completer > I'm talking about.) In this type of situation I usually explicitly press expand-word (^X* by default I believe). -- Mikael Magnusson ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Dynamic named directories and completion 2018-02-26 17:49 ` Mikael Magnusson @ 2018-02-26 17:55 ` Peter Stephenson 0 siblings, 0 replies; 19+ messages in thread From: Peter Stephenson @ 2018-02-26 17:55 UTC (permalink / raw) To: Zsh Users On Mon, 26 Feb 2018 18:49:01 +0100 Mikael Magnusson <mikachu@gmail.com> wrote: > > (Ideally, in fact, whether or not we expand ~[whatever] needs > > configuring --- because this is dynamic completion you might decide to > > expand it to freeze the path for future use. I'll look at that if I get > > the chance. This is the sort of reason for using the expand completer > > I'm talking about.) > > In this type of situation I usually explicitly press expand-word (^X* > by default I believe). Yep, ideally as far as the internal and therefore non-configurable widgets are concerned, I think we want expand-word to expand this and expand-or-complete not to. That's what happens with normal ~, so this should be doable. pws ^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2018-02-26 21:23 UTC | newest] Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-02-22 22:54 Dynamic named directories and completion Scott Frazer 2018-02-23 0:29 ` [RFC PATCH] _path_files: teach zsh_directory_name Takeshi Banse 2018-02-23 1:19 ` _path_files: fix copy paste error Takeshi Banse 2018-02-23 1:30 ` _path_files: fix copy paste error (2/2) Takeshi Banse 2018-02-23 8:01 ` Dynamic named directories and completion Vincent Bernat 2018-02-23 14:41 ` Scott Frazer 2018-02-23 15:02 ` Takeshi Banse 2018-02-23 14:42 ` Scott Frazer 2018-02-24 19:34 ` Peter Stephenson 2018-02-24 19:49 ` Mikael Magnusson 2018-02-24 20:12 ` Peter Stephenson 2018-02-26 14:31 ` Scott Frazer 2018-02-26 13:53 ` Scott Frazer 2018-02-26 14:47 ` Peter Stephenson 2018-02-26 16:44 ` Scott Frazer 2018-02-26 20:08 ` Peter Stephenson 2018-02-26 21:22 ` Peter Stephenson 2018-02-26 17:49 ` Mikael Magnusson 2018-02-26 17:55 ` Peter Stephenson
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).