From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2551 invoked by alias); 12 Dec 2016 05:43:04 -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: X-Seq: 40160 Received: (qmail 1978 invoked from network); 12 Dec 2016 05:43:04 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi0-f66.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.218.66):SA:0(0.2/5.0):. Processed in 1.066015 secs); 12 Dec 2016 05:43:04 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: phy1729@gmail.com 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.218.66 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=REqXRpJZH6d95BNCJz6+3pmm+H4S8niL0wgclsMWLks=; b=bpooSp1EL4tRrlVSoKZ1+4z1OGsi+L0dLB8zng5W9J7GuxVt5fujV5u3TrU+jZCHrs CfOW0Zd4KBiaicNP2jIcxw1QySMKhIZU86Y875BRaLf46+YaS2KbxtBCpfclBpDbep1I JjZxQQycub0zebekwy6lIw8owvmzwuwwjGDEMqHxMQxqNhXxrsV77LlmtESNeQ7whnts OINfm11jV0djX9LK9nEFjhXJn4n3vUfAcLQPoeNSBqP7vkuj8bwoZR4QAzgyAwc2/7fm IIKOnC8O7CdmhmdeW/pjwd8iC4ZnE7Y4DJ+koaRT1OzDY/Nex5tSbOVXsGBPYVtawiHR ZqmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition:user-agent; bh=REqXRpJZH6d95BNCJz6+3pmm+H4S8niL0wgclsMWLks=; b=fbhj6RIyqrz48heKq0lluzvk9UbkK/hdbjay/wGDzt54jQHAVtWXx4ajegmqi5LNDK fNZ5N+XR8qFJ8CWaY7WOcHq726vZRjnhyiv6qKKGcnr7NO1B04W+eiK12odEST//VHl9 i8+5fv7laakIYmW27IbTyiPLh+5fhFpO3GXCxngPg9+dHXSBcTS+yBXvL9HL/y4+ZyON UDe98K1f7KnDqrul+wUTyJv8P/5dUV2I09ImNQ8eOuyVnUXcDhFZ8zqMTQSoQkJ+PY9Y 1r7Il6pVJxdX4K0BHwOYYLuBlCAYLZowemBRO3z5pXzXTo9x7j8ZoSVgoZm1nIHkQuDD 1fDw== X-Gm-Message-State: AKaTC01bemN1DaYJOpSMtU87udeCTKSTQm9gy5vV0irxwBPh756Qd8qUpDFXMyl/2Hd46Q== X-Received: by 10.157.7.38 with SMTP id 35mr54423218ote.87.1481520485269; Sun, 11 Dec 2016 21:28:05 -0800 (PST) Date: Sun, 11 Dec 2016 23:28:03 -0600 From: Matthew Martin To: zsh-workers@zsh.org Subject: _os_arguments Message-ID: <20161212052803.GA53519@CptOrmolo.darkstar> Mail-Followup-To: zsh-workers@zsh.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.2 (2016-11-26) Also for when 5.3 is settled. When updating completions for the BSDs, it can be a bit of a pain to check each case or if block especially since the alphabetization of the options is disrupted. This is an attempt to ease that pain. First an example usage converting _rm to _os_arguments then the patch itself. Hopefully the yodl looks decent. - Matthew Martin diff --git a/Completion/Unix/Command/_rm b/Completion/Unix/Command/_rm index 6d728b157..0c5b526f1 100644 --- a/Completion/Unix/Command/_rm +++ b/Completion/Unix/Command/_rm @@ -23,32 +23,20 @@ if _pick_variant gnu=gnu unix --help; then ) else args=(${args:#*)--*\[*}) - case $OSTYPE in - dragonfly*|freebsd*|netbsd*|openbsd*) - args+=( - '-d[remove directories as well]' - '-P[overwrite files before deleting them]' - ) - ;| - dragonfly*|freebsd*|netbsd*) - args+=( - '-v[explain what is being done]' - '-W[attempt to undelete named files]' - "-x[don't cross file systems when removing a hierarchy]" - ) - ;| - dragonfly*|freebsd*) - args+=( - '(-i)-I[prompt when removing many files]' - ) - ;; - esac + args+=( + DFNO '-d[remove directories as well]' + DF '(-i)-I[prompt when removing many files]' + DFNO '-P[overwrite files before deleting them]' + DFN '-v[explain what is being done]' + DFN '-W[attempt to undelete named files]' + DFN "-x[don't cross file systems when removing a hierarchy]" + ) fi local curcontext=$curcontext state line ret=1 declare -A opt_args -_arguments -C -s $opts \ +_os_arguments -C -s $opts : \ $args && ret=0 case $state in diff --git a/Completion/Base/Utility/_os_arguments b/Completion/Base/Utility/_os_arguments new file mode 100755 index 000000000..44ba19c05 --- /dev/null +++ b/Completion/Base/Utility/_os_arguments @@ -0,0 +1,36 @@ +#autoload + +local i os s=2 +local -a args + +i=${@[(i):]} +(( i > $# )) && i=0 +args=(${@[1,i]}) +shift $i + +case $OSTYPE in + aix*) os=A;; + cygwin*) os=C;; + dragonfly*) os=D;; + freebsd*) os=F;; + hpux*) os=H;; + irix*) os=I;; + linux*) os=L;; + darwin*) os=M;; + netbsd*) os=N;; + openbsd*) os=O;; + solaris*) os=S;; +esac + +for 1; do + if [[ $1 == [[:upper:]]## ]]; then + (( s == 2 )) && s=0 + [[ $1 == *$os* ]] && s=1 + else + (( s )) || continue + args+=($1) + s=2 + fi +done + +_arguments "$args[@]" diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 953d51c4c..e75aa7062 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -4624,6 +4624,60 @@ are used to store the option settings in effect before the completion widget locally sets the options it needs. Hence these functions are not generally used by the completion system. ) +findex(_os_arguments) +xitem(tt(_os_arguments )[ var(_arguments flags) tt(:) ] {var(OS selector)|var(spec)} ) +This function wraps tt(_arguments) to ease completing multiple OSes with +differing flags. The arguments up to the first colon are passed verbatim +to tt(_arguments). Following arguments are either OS selectors, +consisting of all uppercase letters, or tt(_arguments) specs. Each OS is +assigned a letter (see below). If that letter appears in an OS selector +since the last spec (or if there is no proceeding OS selector), the +following specs are passed to tt(_arguments) until the next OS selector. + +startitem() +item(tt(A))( +AIX +) +item(tt(C))( +Cygwin +) +item(tt(D))( +DragonFlyBSD +) +item(tt(F))( +FreeBSD +) +item(tt(H))( +HP-UX +) +item(tt(I))( +IRIX +) +item(tt(L))( +Linux +) +item(tt(M))( +macOS +) +item(tt(N))( +NetBSD +) +item(tt(O))( +OpenBSD +) +item(tt(S))( +Solaris +) +enditem() + +example(_os_arguments -s : \\ \ + '-n[number all output lines]' \\ \ + '-u[do not buffer output]' \\ \ + '(-)*:files:_files' \\ \ + N '-B[use specified buffer size]:buffer size:' \\ \ + F N '-l[set a lock on the stdout file descriptor]' \\ \ + DFMNO '-v[display non-printing chars as ^X or M-a]' +) findex(_parameters) item(tt(_parameters))( This is used to complete the names of shell parameters.