zsh-workers
 help / color / mirror / code / Atom feed
312d0a7a0401388e74493370599e0f961feef5b7 blob 2777 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
78
 
#autoload

# Usage: _numbers [compadd options] [-t tag] [-f|-N] [-u units] [-l min] [-m max] \
#                 [-d default] ["description"] [unit-suffix...]

#   -t : specify a tag (defaults to 'numbers')
#   -u : indicate the units, e.g. seconds
#   -l : lowest possible value
#   -m : maximum possible value
#   -d : default value
#   -N : allow negative numbers (implied by range including a negative)
#   -f : allow decimals (float)

# For a unit-suffix, an initial colon indicates a unit that asserts the default
# otherwise, colons allow for descriptions, e.g:

#   :s:seconds m:minutes h:hours

# unit-suffixes are not sorted by the completion system when listed
# Specify them in order of magnitude, this tends to be ascending unless
# the default is of a higher magnitude, in which case, descending.
# So for, example
#   bytes kB MB GB
#   s ms us ns
# Where the compadd options include matching control or suffixes, these
# are applied to the units

# For each unit-suffix, the format style is looked up with the
# unit-suffixes tag and the results concatenated.

# _description is called with u and U tokens set

local desc tag range suffixes suffix suffixfmt pat='<->' partial=''
local -a expl formats
local -a default max min keep tags units
local -i i
local -A opts

zparseopts -K -D -A opts M+:=keep q:=keep s+:=keep S+:=keep J+: V+: 1 2 o+: n F: x+: X+: \
  t:=tags u:=units l:=min m:=max d:=default f=type e=type N=type

desc="${1:-number}" tag="${tags[2]:-numbers}"
(( $# )) && shift

[[ -n ${(M)type:#-f} ]] && pat='(<->.[0-9]#|[0-9]#.<->|<->)' partial='(|.)'
[[ -n ${(M)type:#-N} || $min[2] = -* || $max[2] = -* ]] && \
    pat="(|-)$pat" partial="(|-)$partial"

if (( $#argv )) && compset -P "$pat"; then
  zstyle -s ":completion:${curcontext}:units" list-separator sep || sep=--
  _description -V units expl unit
  disp=( ${${argv#:}/:/ $sep } )
  compadd -M 'r:|/=* r:|=*' -d disp "$keep[@]" "$expl[@]" - ${${argv#:}%%:*}
  return
elif [[ -prefix $~pat || $PREFIX = $~partial ]]; then
  formats=( "h:$desc" H:1 )
  (( $#units )) && formats+=( m:${units[2]} M:${#units} ) desc+=" ($units[2])"
  (( $#min )) && range="$min[2]-"
  (( $#max )) && range="${range:--}$max[2]"
  [[ -n $range ]] && formats+=( r:$range R:1 ) desc+=" ($range)"
  (( $#default )) && formats+=( o:${default[2]} O:1 ) desc+=" [$default[2]]"

  zstyle -s ":completion:${curcontext}:unit-suffixes" format suffixfmt
  for ((i=0;i<$#;i++)); do
    zformat -f suffix "$suffixfmt" "x:${${argv[i+1]#:}%%:*}" \
        "X:${${argv[i+1]#:}#*:}" "d:${#${argv[i+1]}[1]#:}" \
	i:i r:$(( $# - i - 1))
    suffixes+="$suffix"
  done
  [[ -n $suffixes ]] && formats+=( x:$suffixes X:1 )

  _comp_mesg=yes
  _description -x $tag expl "$desc" $formats
  compadd "$expl[@]"
  return 0
fi

return 1
debug log:

solving 312d0a7a0 ...
found 312d0a7a0 in https://inbox.vuxu.org/zsh-workers/89303-1635367918.379239@3fX8._yj_.piD6/

applying [1/1] https://inbox.vuxu.org/zsh-workers/89303-1635367918.379239@3fX8._yj_.piD6/
diff --git a/Completion/Base/Utility/_numbers b/Completion/Base/Utility/_numbers
new file mode 100644
index 000000000..312d0a7a0

Checking patch Completion/Base/Utility/_numbers...
Applied patch Completion/Base/Utility/_numbers cleanly.

index at:
100644 312d0a7a0401388e74493370599e0f961feef5b7	Completion/Base/Utility/_numbers

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