From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15137 invoked by alias); 7 May 2016 22:09:32 -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: 38422 Received: (qmail 27433 invoked from network); 7 May 2016 22:09:27 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 From: Frank Terbeck To: zsh-workers@zsh.org Cc: Oliver Kiddle Subject: [PATCH 1/6] =?UTF-8?q?=5Fbaudrate=20=E2=86=92=20=5Fbaudrates?= Date: Sun, 8 May 2016 00:09:11 +0200 Message-Id: <1462658956-11785-2-git-send-email-ft@bewatermyfriend.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1462658956-11785-1-git-send-email-ft@bewatermyfriend.org> References: <27858.1462193719@thecus.kiddle.eu> <1462658956-11785-1-git-send-email-ft@bewatermyfriend.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Df-Sender: NDMwNDQ0 Oliver notes that helper functions usually have plural names by convention. --- Completion/Unix/Type/_baudrate | 84 ----------------------------------------- Completion/Unix/Type/_baudrates | 84 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 84 deletions(-) delete mode 100644 Completion/Unix/Type/_baudrate create mode 100644 Completion/Unix/Type/_baudrates diff --git a/Completion/Unix/Type/_baudrate b/Completion/Unix/Type/_baudrate deleted file mode 100644 index c169284..0000000 --- a/Completion/Unix/Type/_baudrate +++ /dev/null @@ -1,84 +0,0 @@ -#autoload - -# Offer a list of baud-rates. Usage: -# -# _baudrate [OPTION(s)...] -# -# Available options: -# -# -u LIMIT Upper limit. LIMIT is the maximum value the offered list -# will contain, if the complete list includes LIMIT exactly. -# -# -l LIMIT Lower limit. Like -u but for the lower boundary. -# -# -f FUNCTION If given FUNCION is used as a predicate to filter the -# value in the complete list to generate an arbitrary -# sub-set. -# -# -t TAG Use TAG as the tag value in _wanted call. -# -# -d DESC Use DESC as the description value in _wanted call. -# -# The default complete list of available baud rates is also configurable via -# the 'baud-rates' style: -# -# zstyle ':completion:*' baud-rates 23 42 666 -# -# It is also possible to override the arguments to -f, -u and -l via styles in -# a similar fashion: -# -# zstyle ':completion:*:*:screen:*' max-baud-rate 9600 -# zstyle ':completion:*:*:screen:*' min-baud-rate 1200 -# zstyle ':completion:*:*:screen:*' baud-rate-filter some_function_name - -local -A opts -local expl tag desc tmp -local -a rates - -zparseopts -E -A opts u: l: f: d: t: - -# The following uses a generated list; first find out where the B* macros are -# defined: -# -# grep -r B115200 /usr/include -# -# Then generate the actual list: -# -# sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \ -# < /usr/include/asm-generic/termbits.h -# -# This one was generated on a Debian Stretch system, leaving out the "0" rate, -# which is synonymous to "hang-up". - -zstyle -a ":completion:${curcontext}:" baud-rates rates || - rates=( 50 75 110 134 150 200 300 600 - 1200 1800 2400 4800 9600 - 19200 38400 57600 - 115200 230400 460800 500000 576000 921600 - 1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 ) - -zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp -zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp -zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp - -if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then - local -i min max - min=${opts[-l]:-0} - max=${opts[-u]:-${${(On)rates}[1]}} - rates=( ${(M)rates:#${~:-<$min-$max>}} ) -fi - -if (( ${+opts[-f]} )); then - set -- $rates - rates=( ) - for item; do - ${opts[-f]} $item && rates+=( $item ) - done -fi - -tag=${opts[-t]:-baud-rate} -desc=${opts[-d]:-baud rate} - -# -1V removes dupes (which there shouldn't be) and otherwise leaves the -# order in the $rates array intact. -_wanted -1V $tag expl $desc compadd -a $expl -- rates diff --git a/Completion/Unix/Type/_baudrates b/Completion/Unix/Type/_baudrates new file mode 100644 index 0000000..9e87e7a --- /dev/null +++ b/Completion/Unix/Type/_baudrates @@ -0,0 +1,84 @@ +#autoload + +# Offer a list of baud-rates. Usage: +# +# _baudrates [OPTION(s)...] +# +# Available options: +# +# -u LIMIT Upper limit. LIMIT is the maximum value the offered list +# will contain, if the complete list includes LIMIT exactly. +# +# -l LIMIT Lower limit. Like -u but for the lower boundary. +# +# -f FUNCTION If given FUNCION is used as a predicate to filter the +# value in the complete list to generate an arbitrary +# sub-set. +# +# -t TAG Use TAG as the tag value in _wanted call. +# +# -d DESC Use DESC as the description value in _wanted call. +# +# The default complete list of available baud rates is also configurable via +# the 'baud-rates' style: +# +# zstyle ':completion:*' baud-rates 23 42 666 +# +# It is also possible to override the arguments to -f, -u and -l via styles in +# a similar fashion: +# +# zstyle ':completion:*:*:screen:*' max-baud-rate 9600 +# zstyle ':completion:*:*:screen:*' min-baud-rate 1200 +# zstyle ':completion:*:*:screen:*' baud-rate-filter some_function_name + +local -A opts +local expl tag desc tmp +local -a rates + +zparseopts -E -A opts u: l: f: d: t: + +# The following uses a generated list; first find out where the B* macros are +# defined: +# +# grep -r B115200 /usr/include +# +# Then generate the actual list: +# +# sed -ne '/^[ \t]*#define[ \t]*B[0-9][0-9]*/s,^.*B\([0-9][0-9]*\).*,\1,p' \ +# < /usr/include/asm-generic/termbits.h +# +# This one was generated on a Debian Stretch system, leaving out the "0" rate, +# which is synonymous to "hang-up". + +zstyle -a ":completion:${curcontext}:" baud-rates rates || + rates=( 50 75 110 134 150 200 300 600 + 1200 1800 2400 4800 9600 + 19200 38400 57600 + 115200 230400 460800 500000 576000 921600 + 1000000 1152000 1500000 2000000 2500000 3000000 3500000 4000000 ) + +zstyle -s ":completion:${curcontext}:" max-baud-rate tmp && opts[-u]=$tmp +zstyle -s ":completion:${curcontext}:" min-baud-rate tmp && opts[-l]=$tmp +zstyle -s ":completion:${curcontext}:" baud-rate-filter tmp && opts[-f]=$tmp + +if (( ${+opts[-u]} )) || (( ${+opts[-l]} )); then + local -i min max + min=${opts[-l]:-0} + max=${opts[-u]:-${${(On)rates}[1]}} + rates=( ${(M)rates:#${~:-<$min-$max>}} ) +fi + +if (( ${+opts[-f]} )); then + set -- $rates + rates=( ) + for item; do + ${opts[-f]} $item && rates+=( $item ) + done +fi + +tag=${opts[-t]:-baud-rate} +desc=${opts[-d]:-baud rate} + +# -1V removes dupes (which there shouldn't be) and otherwise leaves the +# order in the $rates array intact. +_wanted -1V $tag expl $desc compadd -a $expl -- rates -- 2.8.1