zsh-workers
 help / color / mirror / code / Atom feed
From: German Riano <griano@yahoo.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: PATCH: Improve quote handling in _ant completion
Date: Wed, 29 Nov 2023 01:28:52 +0000 (UTC)	[thread overview]
Message-ID: <207461559.9336309.1701221332233@mail.yahoo.com> (raw)
In-Reply-To: <207461559.9336309.1701221332233.ref@mail.yahoo.com>

[-- Attachment #1: Type: text/plain, Size: 2930 bytes --]

In the current completion, if a task description contains a quote (') the completions do not render properly
In this patch I propose to build the tmp array via
tmp=( ${(f@)"$(command)"} )
and print one line at a time. This way quotes are handled correctly
Also I am proposing to shield 'find_targets' with '(( $#functions[find_targets] )) ||' so that users can easily override the function.



Germán Riaño, Ph. D. http://GermanRiano.com Seattle, WA, USA

diff --git a/Completion/Unix/Command/_ant b/Completion/Unix/Command/_ant
index 36c7c0e89..c7bc7eb5f 100644
--- a/Completion/Unix/Command/_ant
+++ b/Completion/Unix/Command/_ant
@@ -6,6 +6,7 @@ local curcontext="$curcontext" state line expl ret=1
 typeset -A opt_args
 local buildfile classpath cp userjars importedfiles target='*:target:->target' targets tmp
 
+(( $#functions[find_targets] )) ||
 find_targets() {
     importedfiles=( $(sed -n "s/ *<import[^>]* file=[\"']\([^\"']*\)[\"'].*/\1/p" < $1) )
     # Tweaked to omit targets beginning with "-" that can't
@@ -103,8 +104,8 @@ case $state in
         # For the array to be set with correct argument boundaries, the entire
         # set statement needs to be eval'd.  On Cygwin, need to kill \r's output
         # from Java or parsing will fail.
-        eval set -A tmp "${$(_call_program targets "$words[1]" -buildfile $buildfile -projecthelp |
-          while read target desc
+        tmp=(${(f@)"$(_call_program targets "$words[1]" -buildfile $buildfile -projecthelp |
+          while read -r target desc
           do
             # This loop reads ant -projecthelp output from versions 1.3 to 1.6
             ln="${target}${desc:+:$desc}"
@@ -122,17 +123,18 @@ case $state in
                         read default_target junk
                     fi
                     # Output target again indicating its the default one.
-                    print -n "'${default_target}:(Default target) ' "
+                    print -- "${default_target}:(Default target)"
                 ;;
                 (Searching:*|Main:targets:|Subtargets:|BUILD:SUCCESSFUL|Total:time:*)
                 ;;
                 (*)
                     # Return target and description
-                    print -n "'$ln' "
+                    print -- "$ln"
                 ;;
             esac
           done
-        )//$'\015'}"
+        )"//$'\015'})
+
         _describe 'target' tmp && ret=0
       else
         targets=( $(find_targets $buildfile) )



[-- Attachment #2: Type: text/html, Size: 5406 bytes --]

       reply	other threads:[~2023-11-29  1:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <207461559.9336309.1701221332233.ref@mail.yahoo.com>
2023-11-29  1:28 ` German Riano [this message]
2023-11-29 19:18   ` Bart Schaefer
2023-11-29 19:19     ` Bart Schaefer
2023-11-29 19:56     ` Mikael Magnusson
2023-11-29 23:44       ` Bart Schaefer
2023-11-30  0:15         ` German Riano
2023-11-30  0:52           ` Bart Schaefer
2023-11-30  1:28             ` German Riano
2023-11-30  2:40               ` Bart Schaefer
2023-12-01 19:20                 ` German Riano
2023-12-02 23:21                   ` Bart Schaefer
2023-12-02 23:31       ` Bart Schaefer
2023-12-03 21:08         ` Oliver Kiddle
2023-12-04  0:05           ` Bart Schaefer
2023-12-04  0:11             ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=207461559.9336309.1701221332233@mail.yahoo.com \
    --to=griano@yahoo.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).