#compdef example # This script was generated by crazy-complete. # crazy-complete: A tool that creates robust and reliable autocompletion scripts for Bash, Fish and Zsh. # For more information, visit: https://github.com/crazy-complete/crazy-complete _example__query() { __zsh_query_contains() { local arg='' key="$1"; shift for arg; do [[ "$key" == "$arg" ]] && return 0; done return 1 } local cmd="$1"; shift case "$cmd" in get_positional) printf "%s" "${POSITIONALS[$1]}" return 0;; has_option) local option='' with_incomplete=0 [[ "$1" == 'WITH_INCOMPLETE' ]] && { with_incomplete=1; shift; } for option in "${HAVING_OPTIONS[@]}"; do __zsh_query_contains "$option" "$@" && return 0 done (( with_incomplete )) && \ __zsh_query_contains "$INCOMPLETE_OPTION" "$@" && return 0 return 1;; init) local IFS=',' local -a options=(${=1}) unset IFS shift;; *) echo "_example__query: argv[1]: invalid command" >&2 return 1;; esac local long_opts_with_arg=() long_opts_with_optional_arg=() long_opts_without_arg=() local short_opts_with_arg=() short_opts_with_optional_arg=() short_opts_without_arg=() local option='' for option in "${options[@]}"; do case "$option" in --?*=) long_opts_with_arg+=("${option%=}");; --?*=\?) long_opts_with_optional_arg+=("${option%=?}");; --?*) long_opts_without_arg+=("$option");; -?=) short_opts_with_arg+=("${option%=}");; -?=\?) short_opts_with_optional_arg+=("${option%=?}");; -?) short_opts_without_arg+=("$option");; esac done POSITIONALS=() HAVING_OPTIONS=() OPTION_VALUES=() INCOMPLETE_OPTION='' local argi=2 # argi[1] is program name for ((; argi <= $#; ++argi)); do local arg="${@[$argi]}" local have_trailing_arg=$(test $argi -lt $# && echo true || echo false) case "$arg" in --) POSITIONALS+=("${@:$((argi + 1))}") break;; --*=*) HAVING_OPTIONS+=("${arg%%=*}") OPTION_VALUES+=("${arg#*=}");; --*) if __zsh_query_contains "$arg" "${long_opts_with_arg[@]}"; then if $have_trailing_arg; then HAVING_OPTIONS+=("$arg") OPTION_VALUES+=("${@[$((++argi))]}") else INCOMPLETE_OPTION="$arg" fi else HAVING_OPTIONS+=("$arg") OPTION_VALUES+=("") fi ;; -?*) # ignore '-' local i=1 arg_length=${#arg} for ((; i < arg_length; ++i)); do local option="-${arg:$i:1}" local trailing_chars="${arg:$((i+1))}" if __zsh_query_contains "$option" "${short_opts_without_arg[@]}"; then HAVING_OPTIONS+=("$option") OPTION_VALUES+=("") elif __zsh_query_contains "$option" "${short_opts_with_arg[@]}"; then if [[ -n "$trailing_chars" ]]; then HAVING_OPTIONS+=("$option") OPTION_VALUES+=("$trailing_chars") elif $have_trailing_arg; then HAVING_OPTIONS+=("$option") OPTION_VALUES+=("${@[$((++argi))]}") else INCOMPLETE_OPTION="$option" fi continue 2 elif __zsh_query_contains "$option" "${short_opts_with_optional_arg[@]}"; then HAVING_OPTIONS+=("$option") OPTION_VALUES+=("$trailing_chars") # may be empty continue 2 fi done ;; *) POSITIONALS+=("$arg");; esac done } _example_start__--preserve-env() { _parameters -g '*export*' } _example_start__--priority() { local items=( low:'Run with lowest priority, background tasks only' normal:'Standard scheduling priority for regular tasks' high:'Higher priority for time-sensitive operations' realtime:'Real-time scheduling, may affect system responsiveness' ) _describe -- '' items } _example_start__-o() { _values -s , -S = '' \ lang'[set language]':::_locales \ user'[set user]':::_users \ group'[set group]':::_groups } _example() { local opts=-h,--help local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION='' _example__query init "$opts" "${words[@]}" case "$(_example__query get_positional 1)" in start|launch) _example_start; return $?;; view-log) _example_view_log; return $?;; esac local -a args=( '(- *)'{-h,--help} 1:command1:'((start launch view-log))' ) _arguments -S -s -w "${args[@]}" } _example_start() { local opts=-v,--verbose,--deprecated-option,--preserve-env=,--priority=,--foreground,--background,--pid-file=,-o=,--options=,-h,--help local HAVING_OPTIONS=() OPTION_VALUES=() POSITIONALS=() INCOMPLETE_OPTION='' _example__query init "$opts" "${words[@]}" local -a args=( '*'{-v,--verbose} '(--preserve-env)'--preserve-env=:' ':'_sequence _example_start__--preserve-env' '(--priority)'--priority=:' ':_example_start__--priority '(--background --foreground)'--foreground '(--foreground --background)'--background '(--options -o)'{-o+,--options=}:' ':'{_example_start__-o}' '(- *)'{-h,--help} 1:command1:'((start launch view-log))' 2:command:_command_names '*'::argument:_normal ) _example__query has_option WITH_INCOMPLETE --deprecated-option &&\ args+=('(--deprecated-option)'--deprecated-option) _example__query has_option --background &&\ args+=('(--pid-file)'--pid-file=:' ':_files) _arguments -S -s -w "${args[@]}" } _example_view_log() { local -a args=( '(--pager)'--pager=-:command:_command_names '(- *)'{-h,--help} 1:command1:'((start launch view-log))' ) _arguments -S -s -w "${args[@]}" } zstyle ':completion:*:*:example:option--priority-*' sort false _example "$@" # vim: ft=zsh ts=2 sts=2 sw=2 et