zsh-workers
 help / color / mirror / code / Atom feed
872e8f5830f8368ec218f2079e0da46bd24ecd5f blob 1482 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
 
#autoload

local output cmd pat pre
local -a var
local -A opts

# Precommands which allow their wrapped command to be a builtin.
# All of these are necessarily builtins or reserved words themselves,
# but not all builtin precommands are listed here:
# for one, the 'command' builtin is excluded.
local -ar builtin_precommands=(- builtin eval exec nocorrect noglob time)

(( $+_cmd_variant )) || typeset -gA _cmd_variant

zparseopts -D -A opts b: c: r:
: ${opts[-c]:=$words[1]}

while [[ $1 = *=* ]]; do
  var+=( "${1%%\=*}" "${1#*=}" )
  shift
done

if (( ${#precommands:|builtin_precommands} )); then
  pre=command
elif (( $+opts[-b] && ( $precommands[(I)builtin] || $+builtins[$opts[-c]] ) )); then
  (( $+opts[-r] )) && eval "${opts[-r]}=$opts[-b]"
  return 0
elif (( $precommands[(I)builtin] )); then
  pre=builtin
else
  # Neither builtin nor command-forcing precommand specified,
  # so no prefix is needed.
  pre=
fi

if [[ $pre != builtin ]] && (( $+_cmd_variant[$opts[-c]] )); then
  (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}"
  [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1
  return 0
fi

output="$(_call_program variant $pre $opts[-c] "${@[2,-1]}" </dev/null 2>&1)"

for cmd pat in "$var[@]"; do
  if [[ $output = *$~pat* ]]; then
    (( $+opts[-r] )) && eval "${opts[-r]}=$cmd"
    _cmd_variant[$opts[-c]]="$cmd"
    return 0
  fi
done

(( $+opts[-r] )) && eval "${opts[-r]}=$1"
[[ $pre != builtin ]] && _cmd_variant[$opts[-c]]="$1"

return 1
debug log:

solving 872e8f583 ...
found 872e8f583 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).