| 1 |
#compdef example |
| 2 |
|
| 3 |
# This script was generated by crazy-complete. |
| 4 |
# crazy-complete: A tool that creates robust and reliable autocompletion scripts for Bash, Fish and Zsh. |
| 5 |
# For more information, visit: https://github.com/crazy-complete/crazy-complete |
| 6 |
|
| 7 |
_example__query() { |
| 8 |
|
| 9 |
__zsh_query_contains() { |
| 10 |
local arg='' key="$1"; shift |
| 11 |
for arg; do [[ "$key" == "$arg" ]] && return 0; done |
| 12 |
return 1 |
| 13 |
} |
| 14 |
|
| 15 |
local cmd="$1"; shift |
| 16 |
|
| 17 |
case "$cmd" in |
| 18 |
get_positional) |
| 19 |
printf "%s" "${POSITIONALS[$1]}" |
| 20 |
return 0;; |
| 21 |
has_option) |
| 22 |
local option='' with_incomplete=0 |
| 23 |
[[ "$1" == 'WITH_INCOMPLETE' ]] && { with_incomplete=1; shift; } |
| 24 |
|
| 25 |
for option in "${HAVING_OPTIONS[@]}"; do |
| 26 |
__zsh_query_contains "$option" "$@" && return 0 |
| 27 |
done |
| 28 |
|
| 29 |
(( with_incomplete )) && \ |
| 30 |
__zsh_query_contains "$INCOMPLETE_OPTION" "$@" && return 0 |
| 31 |
|
| 32 |
return 1;; |
| 33 |
init) |
| 34 |
local IFS=',' |
| 35 |
local -a options=(${=1}) |
| 36 |
unset IFS |
| 37 |
shift;; |
| 38 |
*) |
| 39 |
echo "_example__query: argv[1]: invalid command" >&2 |
| 40 |
return 1;; |
| 41 |
esac |
| 42 |
|
| 43 |
|
| 44 |
local long_opts_with_arg=() long_opts_with_optional_arg=() long_opts_without_arg=() |
| 45 |
local short_opts_with_arg=() short_opts_with_optional_arg=() short_opts_without_arg=() |
| 46 |
|
| 47 |
local option='' |
| 48 |
for option in "${options[@]}"; do |
| 49 |
case "$option" in |
| 50 |
--?*=) long_opts_with_arg+=("${option%=}");; |
| 51 |
--?*=\?) long_opts_with_optional_arg+=("${option%=?}");; |
| 52 |
--?*) long_opts_without_arg+=("$option");; |
| 53 |
-?=) short_opts_with_arg+=("${option%=}");; |
| 54 |
-?=\?) short_opts_with_optional_arg+=("${option%=?}");; |
| 55 |
-?) short_opts_without_arg+=("$option");; |
| 56 |
esac |
| 57 |
done |
| 58 |
|
| 59 |
POSITIONALS=() |
| 60 |
HAVING_OPTIONS=() |
| 61 |
OPTION_VALUES=() |
| 62 |
INCOMPLETE_OPTION='' |
| 63 |
|
| 64 |
local argi=2 # argi[1] is program name |
| 65 |
for ((; argi <= $#; ++argi)); do |
| 66 |
local arg="${@[$argi]}" |
| 67 |
local have_trailing_arg=$(test $argi -lt $# && echo true || echo false) |
| 68 |
|
| 69 |
case "$arg" in |
| 70 |
--) |
| 71 |
POSITIONALS+=("${@:$((argi + 1))}") |
| 72 |
break;; |
| 73 |
--*=*) |
| 74 |
HAVING_OPTIONS+=("${arg%%=*}") |
| 75 |
OPTION_VALUES+=("${arg#*=}");; |
| 76 |
--*) |
| 77 |
if __zsh_query_contains "$arg" "${long_opts_with_arg[@]}"; then |
| 78 |
if $have_trailing_arg; then |
| 79 |
HAVING_OPTIONS+=("$arg") |
| 80 |
OPTION_VALUES+=("${@[$((++argi))]}") |
| 81 |
else |
| 82 |
INCOMPLETE_OPTION="$arg" |
| 83 |
fi |
| 84 |
else |
| 85 |
HAVING_OPTIONS+=("$arg") |
| 86 |
OPTION_VALUES+=("") |
| 87 |
fi |
| 88 |
;; |
| 89 |
-?*) # ignore '-' |
| 90 |
|
| 91 |
local i=1 arg_length=${#arg} |
| 92 |
for ((; i < arg_length; ++i)); do |
| 93 |
local option="-${arg:$i:1}" |
| 94 |
local trailing_chars="${arg:$((i+1))}" |
| 95 |
|
| 96 |
if __zsh_query_contains "$option" "${short_opts_without_arg[@]}"; then |
| 97 |
HAVING_OPTIONS+=("$option") |
| 98 |
OPTION_VALUES+=("") |
| 99 |
elif __zsh_query_contains "$option" "${short_opts_with_arg[@]}"; then |
| 100 |
if [[ -n "$trailing_chars" ]]; then |
| 101 |
HAVING_OPTIONS+=("$option") |
| 102 |
OPTION_VALUES+=("$trailing_chars") |
| 103 |
elif $have_trailing_arg; then |
| 104 |
HAVING_OPTIONS+=("$option") |
| 105 |
OPTION_VALUES+=("${@[$((++argi))]}") |
| 106 |
else |
| 107 |
INCOMPLETE_OPTION="$option" |
| 108 |
fi |
| 109 |
|
| 110 |
continue 2 |
| 111 |
elif __zsh_query_contains "$option" "${short_opts_with_optional_arg[@]}"; then |
| 112 |
HAVING_OPTIONS+=("$option") |
| 113 |
OPTION_VALUES+=("$trailing_chars") # may be empty |
| 114 |
continue 2 |
| 115 |
fi |
| 116 |
done |
| 117 |
;; |
| 118 |
*) |
| 119 |
POSITIONALS+=("$arg");; |
| 120 |
esac |
| 121 |
done |
| 122 |
} |
| 123 |
|
| 124 |
_example_start__--preserve-env() { |
| 125 |
_parameters -g '*export*' |
| 126 |
} |
| 127 |
|
| 128 |
_example_start__--priority() { |
| 129 |
local items=( |
| 130 |
low:'Run with lowest priority, background tasks only' |
| 131 |
normal:'Standard scheduling priority for regular tasks' |
| 132 |
high:'Higher priority for time-sensitive operations' |
| 133 |
realtime:'Real-time scheduling, may affect system responsiveness' |
| 134 |
) |
| 135 |
|
| 136 |
_describe -- '' items |
| 137 |
} |
| 138 |
|
| 139 |
_example_start__-o() { |
| 140 |
_values -s , -S = '' \ |
| 141 |
lang'[set language]':::_locales \ |
| 142 |
user'[set user]':::_users \ |
| 143 |
group'[set group]':::_groups |
| 144 |
} |
| 145 |
|
| 146 |
_example() { |
| 147 |
local opts=-h,--help |
| 148 |
local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION='' |
| 149 |
_example__query init "$opts" "${words[@]}" |
| 150 |
|
| 151 |
case "$(_example__query get_positional 1)" in |
| 152 |
start|launch) _example_start; return $?;; |
| 153 |
view-log) _example_view_log; return $?;; |
| 154 |
esac |
| 155 |
|
| 156 |
local -a args=( |
| 157 |
'(- *)'{-h,--help} |
| 158 |
1:command1:'((start launch view-log))' |
| 159 |
) |
| 160 |
_arguments -S -s -w "${args[@]}" |
| 161 |
} |
| 162 |
|
| 163 |
_example_start() { |
| 164 |
local opts=-v,--verbose,--deprecated-option,--preserve-env=,--priority=,--foreground,--background,--pid-file=,-o=,--options=,-h,--help |
| 165 |
local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION='' |
| 166 |
_example__query init "$opts" "${words[@]}" |
| 167 |
|
| 168 |
local -a args=( |
| 169 |
'*'{-v,--verbose} |
| 170 |
'(--preserve-env)'--preserve-env=:' ':'_sequence _example_start__--preserve-env' |
| 171 |
'(--priority)'--priority=:' ':_example_start__--priority |
| 172 |
'(--background --foreground)'--foreground |
| 173 |
'(--foreground --background)'--background |
| 174 |
'(--options -o)'{-o+,--options=}:' ':'{_example_start__-o}' |
| 175 |
'(- *)'{-h,--help} |
| 176 |
1:command1:'((start launch view-log))' |
| 177 |
2:command:_command_names |
| 178 |
'*'::argument:_normal |
| 179 |
) |
| 180 |
_example__query has_option WITH_INCOMPLETE --deprecated-option &&\ |
| 181 |
args+=('(--deprecated-option)'--deprecated-option) |
| 182 |
_example__query has_option --background &&\ |
| 183 |
args+=('(--pid-file)'--pid-file=:' ':_files) |
| 184 |
_arguments -S -s -w "${args[@]}" |
| 185 |
} |
| 186 |
|
| 187 |
_example_view_log() { |
| 188 |
local -a args=( |
| 189 |
'(--pager)'--pager=-:command:_command_names |
| 190 |
'(- *)'{-h,--help} |
| 191 |
1:command1:'((start launch view-log))' |
| 192 |
) |
| 193 |
_arguments -S -s -w "${args[@]}" |
| 194 |
} |
| 195 |
|
| 196 |
zstyle ':completion:*:*:example:option--priority-*' sort false |
| 197 |
|
| 198 |
_example "$@" |
| 199 |
|
| 200 |
# vim: ft=zsh ts=2 sts=2 sw=2 et |