zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Handle completer filenames with funny characters in them
@ 2024-03-18 15:17 Mikael Magnusson
  2024-06-08 13:55 ` Jun. T
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2024-03-18 15:17 UTC (permalink / raw)
  To: zsh-workers

For example, a file called _foo;bar will cause this to happen:
% hello [press tab]zsh: command not found: _foo
zsh: command not found: bar

I'll admit I'm not sure if adding the -r for compassocs at the end is
correct, the array is empty for me and I don't know what it's for.
---
 Completion/compdump | 6 +++---
 Completion/compinit | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Completion/compdump b/Completion/compdump
index 6daf92f9ff..5af5174f12 100644
--- a/Completion/compdump
+++ b/Completion/compdump
@@ -113,7 +113,7 @@ integer _i=5
 print -n autoload -Uz >& $_d_fd
 while (( $#_d_als )); do
   if (( ! $+_compautos[$_d_als[1]] )); then
-    print -n " $_d_als[1]"
+    print -rn " ${(q-)_d_als[1]}"
     if (( ! --_i && $#_d_als > 1 )); then
       _i=5
       print -n ' \\\n           '
@@ -126,13 +126,13 @@ print >& $_d_fd
 
 local _c
 for _c in "${(ok@)_compautos}"; do
-  print "autoload -Uz $_compautos[$_c] $_c" >& $_d_fd
+  print -r "autoload -Uz ${(q-)_compautos[$_c]} $_c" >& $_d_fd
 done
 
 print >& $_d_fd
 
 print "typeset -gUa _comp_assocs" >& $_d_fd
-print "_comp_assocs=( ${(qq)_comp_assocs} )" >& $_d_fd
+print -r "_comp_assocs=( ${(qq)_comp_assocs} )" >& $_d_fd
 exec {_d_fd}>&-
 
 mv -f $_d_file ${_d_file%.$HOST.$$}
diff --git a/Completion/compinit b/Completion/compinit
index 5cb527fac8..51e9d88b83 100644
--- a/Completion/compinit
+++ b/Completion/compinit
@@ -301,7 +301,7 @@ compdef() {
     if [[ -z "$eval" ]] && [[ "$1" = *\=* ]]; then
       while (( $# )); do
         if [[ "$1" = *\=* ]]; then
-	  cmd="${1%%\=*}"
+	  cmd="${(q)${1%%\=*}}"
 	  svc="${1#*\=}"
           func="$_comps[${_services[(r)$svc]:-$svc}]"
           [[ -n ${_services[$svc]} ]] &&
@@ -412,7 +412,7 @@ compdef() {
 	      svc=
             fi
             if [[ -z "$new" || -z "${_comps[$1]}" ]]; then
-              _comps[$cmd]="$func"
+              _comps[$cmd]="${(q)func}"
 	      [[ -n "$svc" ]] && _services[$cmd]="${1#*\=}"
 	    fi
             ;;
-- 
2.38.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Handle completer filenames with funny characters in them
  2024-03-18 15:17 PATCH: Handle completer filenames with funny characters in them Mikael Magnusson
@ 2024-06-08 13:55 ` Jun. T
  2024-06-08 15:49   ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: Jun. T @ 2024-06-08 13:55 UTC (permalink / raw)
  To: zsh-workers


> 2024/03/19 0:17、Mikael Magnusson <mikachu@gmail.com>のメール:
> 
> For example, a file called _foo;bar will cause this to happen:
> % hello [press tab]zsh: command not found: _foo
> zsh: command not found: bar

With this patch the following has stopped working:

% compdef '_files -g "*.h"' foo
% foo <TAB>
foo (eval):1: command not found: _files -g "*.h"

> @@ -412,7 +412,7 @@ compdef() {
> 	      svc=
>             fi
>             if [[ -z "$new" || -z "${_comps[$1]}" ]]; then
> -              _comps[$cmd]="$func"
> +              _comps[$cmd]="${(q)func}"
> 	      [[ -n "$svc" ]] && _services[$cmd]="${1#*\=}"
> 	    fi

I don't know what is the best solution.
Quote only if $func is a single word?,
or quote only the first word of $func?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PATCH: Handle completer filenames with funny characters in them
  2024-06-08 13:55 ` Jun. T
@ 2024-06-08 15:49   ` Mikael Magnusson
  0 siblings, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2024-06-08 15:49 UTC (permalink / raw)
  To: Jun. T; +Cc: zsh-workers

On Sat, Jun 8, 2024 at 3:56 PM Jun. T <takimoto-j@kba.biglobe.ne.jp> wrote:
>
>
> > 2024/03/19 0:17、Mikael Magnusson <mikachu@gmail.com>のメール:
> >
> > For example, a file called _foo;bar will cause this to happen:
> > % hello [press tab]zsh: command not found: _foo
> > zsh: command not found: bar
>
> With this patch the following has stopped working:
>
> % compdef '_files -g "*.h"' foo
> % foo <TAB>
> foo (eval):1: command not found: _files -g "*.h"
>
> > @@ -412,7 +412,7 @@ compdef() {
> >             svc=
> >             fi
> >             if [[ -z "$new" || -z "${_comps[$1]}" ]]; then
> > -              _comps[$cmd]="$func"
> > +              _comps[$cmd]="${(q)func}"
> >             [[ -n "$svc" ]] && _services[$cmd]="${1#*\=}"
> >           fi
>
> I don't know what is the best solution.
> Quote only if $func is a single word?,
> or quote only the first word of $func?

Hmm, I thought I was clever, but not clever enough. I should probably
move my quoting to the place that calls compdef with the filename
arguments instead of quoting it inside compdef.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-08 15:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 15:17 PATCH: Handle completer filenames with funny characters in them Mikael Magnusson
2024-06-08 13:55 ` Jun. T
2024-06-08 15:49   ` Mikael Magnusson

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).