* [RFC PATCH] _path_files: teach zsh_directory_name
[not found] <p6nhj1$5nv$1@blaine.gmane.org>
@ 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
0 siblings, 2 replies; 3+ 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] 3+ 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; 3+ 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] 3+ 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; 3+ 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] 3+ messages in thread
end of thread, other threads:[~2018-02-23 1:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <p6nhj1$5nv$1@blaine.gmane.org>
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
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).