zsh-workers
 help / color / mirror / code / Atom feed
6e9ba4d97be3d9d76a984a0e9925788af44d23f4 blob 2429 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
#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.
#
# 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:*:baud-rates' max-value 9600
#   zstyle ':completion:*:*:screen:*:baud-rates' min-value 1200
#   zstyle ':completion:*:*:screen:*:baud-rates' filter some_function_name

local tmp
local -a expl rates
local -A opts

zparseopts -E -A opts u: l: f:

# 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}:baud-rates" max-value tmp && opts[-u]=$tmp
zstyle -s ":completion:${curcontext}:baud-rates" min-value tmp && opts[-l]=$tmp
zstyle -s ":completion:${curcontext}:baud-rates" 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

# -1 removes dupes (which there shouldn't be)
_description -1 -o numeric baud-rates expl 'baud rate'
compadd "${argv[@]}" "$expl[@]" -- "${rates[@]}"
debug log:

solving 6e9ba4d97b ...
found 6e9ba4d97b in https://git.vuxu.org/mirror/zsh/

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).