From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: (qmail 22178 invoked from network); 11 Mar 2020 21:37:35 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from unknown (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTP; 11 Mar 2020 21:37:35 -0000 Received: (qmail 9768 invoked by alias); 11 Mar 2020 21:37:29 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45531 Received: (qmail 10341 invoked by uid 1010); 11 Mar 2020 21:37:29 -0000 X-Qmail-Scanner-Diagnostics: from mail-yw1-f68.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25744. spamassassin: 3.4.2. Clear:RC:0(209.85.161.68):SA:0(-1.9/5.0):. Processed in 2.036454 secs); 11 Mar 2020 21:37:29 -0000 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.161.68 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=4B5W4yHu5e/Rrq+LIX7VwMbyKkXFuQiARK+5cq6B3/k=; b=LfYU/Au4V5XV2EnwRJB2ZP7uT6YmNDV9MdGzbnd566SEo0OttMTAgxa4hnA2NKqDuz fS5ihCrZ8D02yOS5oJx6EB2l/PzR7WxJECwMCVelDRJ2vrKwQ5zSIT4ZXsDGpWbtP49Z 87HGwxSrb1JinmBlqeXnx92g3SWqnaiNhMSF7nXVoEHxyNRhgT+nPmHnzWMaOgS43EIf zECoU9Axk3ywS6O8IDAYymzIy6/jq7zL3u4838EZXliXMC2DHVz3iVUwjphVjtB+7TfA 9trplML2X6n0BzRuJ2gfXGHMrKLXtgtABrrrOF2PqK5Ox9WagjRlfzBQecm4W0Qve4oi i6vw== X-Gm-Message-State: ANhLgQ0QA0VBJK0lDRzhshK9VImjeNGrzouZ/1wxMOHNBuEcJF4rykGU p/0qO1KrqHz3qU1Xv1xMsGAqQ9f+Uhw= X-Google-Smtp-Source: ADFU+vtxwpCm8sM6JYEEFQSoHSabtuj0B8XIeFDNv89XRYUkGcjKqJFeI12UildDwkGCwa9RCXF5vA== X-Received: by 2002:a25:6a82:: with SMTP id f124mr5322580ybc.129.1583962614337; Wed, 11 Mar 2020 14:36:54 -0700 (PDT) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: [PATCH] Improve _sh Message-Id: Date: Wed, 11 Mar 2020 16:36:52 -0500 To: Zsh hackers list X-Mailer: Apple Mail (2.3445.104.11) Was sitting on this: When i was testing _su for workers/45421 i was frustrated by the fact = that it wouldn't complete -c correctly for me, and that's due to the way sh = completion works. _sh is a generic completer for traditional UNIX shells, so it = doesn't really understand the options they take, and only provides very limited completion for -c. It wouldn't be difficult to add full completion for most of the listed = shells, and maybe i'll do that later, but in the mean time: All of the shells in = the #compdef line appear to support the -ceilx options, and in order to = ensure that stuff like `sh -pc ...` works we can just silently ignore any = others. I think that'd be nicer than what we're currently doing, at least? PS: Stacked-option-ignoring doesn't really work here when i have the +x variants added for Bourne shells, due to workers/45422. Since ignoring = those options more accurately is one of the main benefits of this change, i'll probably merge with that line commented out if it goes in first PPS: I added fish to the check for Bourne shells, just in case, but i'm = not going to worry about it for now otherwise dana diff --git a/Completion/Unix/Command/_sh b/Completion/Unix/Command/_sh index 39d299c58..399baa1ed 100644 --- a/Completion/Unix/Command/_sh +++ b/Completion/Unix/Command/_sh @@ -1,14 +1,35 @@ #compdef sh ash csh dash ksh ksh88 ksh93 mksh oksh pdksh rc tcsh yash =20 -if (( CURRENT =3D=3D ${words[(i)-c]} + 1 )); then - _cmdstring -else - local n=3D${words[(b:2:i)[^-]*]} - if (( n <=3D CURRENT )); then - compset -n $n - _alternative \ - 'files:file:_files' \ - 'commands:command:_normal' && return 0 - fi - _default -fi +local bourne argv0 +local -a args all_opts=3D( -{{0..9},{A..Z},{a..z}} ) + +[[ $service =3D=3D (csh|?csh|fish|rc) ]] || bourne=3D1 + +# Bourne-style shells support +x variants +(( bourne )) && all_opts+=3D( ${all_opts/#-/+} ) +# Bourne-style shells take argv[0] as the second argument to -c +(( bourne )) && argv0=3D':argv[0]:' + +# All of the recognised shells support at least these arguments +args=3D( + "(1 -)-c[execute specified command string]: :_cmdstring$argv0" + '-e[exit immediately on non-zero return]' + '-i[act as interactive shell]' + '-l[act as login shell]' + '-x[print command trace]' + '1:script file:_files' + '*:: :_files' +) +# Bourne-style shells support -o/+o option. Not all of them support = -ooption in +# the same argument, but we'll allow it here for those that do +(( bourne )) && args+=3D( + '-o+[set specified option]:option:' + '+o+[unset specified option]:option:' +) +# Since this is a generic function we don't know what other options = these shells +# support, but we don't want them to break the ones listed above, so = we'll just +# ignore any other single-alphanumeric option. Obviously this doesn't = account +# for long options +args+=3D( = '!'${^${all_opts:#(${(~j<|>)${(@M)${(@M)args#(*[\*\)]|)[+-]?}%[+-]?}})}} = ) + +_arguments -s -S -A '-*' : $args