From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9325 invoked by alias); 23 May 2015 10:11:35 -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: 35271 Received: (qmail 6629 invoked from network); 23 May 2015 10:11:30 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=N1H ASuct4kISllA8DwRfdIArTWw=; b=04SGquFYPbTsbd/Ew/DPjj8a0HkQAb4ID9z kbUxnp/eIoAZpLhoT5OYGoj+EGgHfWO8rynJfxTSrdyDDMIA9tFhKjiuda0c+iym IZepI1SrN/V7agX4XGebbLynVzgfOpD4luQoAxKb3kDSGd3D3XjD99U8ELtzmte7 +YumwSNs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=N1 HASuct4kISllA8DwRfdIArTWw=; b=eh1xKUHO3M8KZ8g+7TpsgyG/F+0/59AA/J /f9JFTaw4znKS49fMUMpYqhzvnZgSq0pOu6rsGr8+ErTTpVmNuo2gcXQ5gYfmCdn NfVJevdoFIzn/tnJ6Nvn0gztHxcFBqGCv3Q1O87fRi1AIKkQTJGrTBmGpUzp/Ypm hWgN5/tRs= X-Sasl-enc: VPM3VUA048MNPOAhc432CsjhsetEVIiTFf2PjlxO+gFT 1432375888 Date: Sat, 23 May 2015 10:11:26 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH] New completion: beep. (And a note on _mkdir) Message-ID: <20150523101126.GC1889@tarsus.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) The new completion is appended. It's mostly boilerplate except for the handling of $words/$CURRENT to support specifying the arguments multiple times separated by -n. On another matter, someone left a question in _mkdir about how to detect precommands: 20 _pick_variant -r variant gnu=gnu zsh='\(eval\)' $OSTYPE --help 21 # It can still happen that there is a precommand command or builtin in the line. 22 # In such cases, the variant has to be modified suitably, after further checking 23 # the variant of the _command_ mkdir. 24 25 # I currently don't know of any way to find out what precommands are present on 26 # the line. The variant should be modified like this once a way is found out: 27 28 # if [[ $variant == zsh ]]; then 29 # if [[ $precommand = *command* ]]; then 30 # _mkdir_command () { command mkdir "$@" } 31 # _pick_variant -c _mkdir_command -r variant gnu=gnu unix --help 32 # fi 33 # elif [[ $precommand = *builtin* ]]; then 34 # variant=zsh 35 # fi The answer is, use the $precommands array, like _calendar does. The array is populated by _precommand and used by _main_complete. --- diff --git a/Completion/Unix/Command/_beep b/Completion/Unix/Command/_beep new file mode 100644 index 0000000..c49c097 --- /dev/null +++ b/Completion/Unix/Command/_beep @@ -0,0 +1,50 @@ +#compdef _beep + +# beep [--verbose | --debug] [-e device | --device device] [-f N] [-l N] +# [-r N] [-d N] [-D N] [-s] [-c] +# beep [ OPTIONS ] [-n] [--new] [ OPTIONS ] +# beep [-h] [--help] +# beep [-v] [-V] [--version] + +# We support the -n/--new restart flag, when it is in its own word, by +# stripping all words from the command line that are after the first -n +# following words[CURRENT] or before the first -n preceding it. As far as +# _arguments knows, the -n flag does not exist, and argv should specify +# a single beeping specification. + +## Strip $words[2] through the first -n preceding $words[CURRENT]. +integer specstart +while specstart=$words[(i)(-n|--new)] + (( specstart < CURRENT )) +do + words[2,specstart]=() + (( CURRENT -= specstart - 1)) +done +unset specstart + +## Strip everything in $words after the first -n following $words[CURRENT]. +integer specend +while specend=$words[(I)(-n|--new)] + (( specend > CURRENT )) +do + words[specend,$#words]=() +done +unset specend + +local -a args +args=( + "(--verbose --debug)"{--verbose,--debug}"[enable debug output]" + "(-e --device)"{-e+,--device=}"[specify device to use]:device (default /dev/tty0, /dev/vc/0)" + "-f+:frequency (Hz) as integer or float" + "-l+:duration (ms)" + "-r+:number of repetitions" + "(-D)-d+[delay between beeps]:delay (ms)" + "(-d)-D+[delay after each beep]:delay (ms)" + "(-n --new)"{-n,--new}"[start a new beeping specification]" + "-s[cat, and beep after each line]" + "-c[cat, and beep after each character]" + "(-)"{-h,--help}"[display usage info]" + "(-)"{-v,-V,--version}"[display version info]" +) + +_arguments -s -S -w : $args