1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-10-03 17:31:33 +02:00
zsh/Completion/Debian/_apt

482 lines
16 KiB
Plaintext

#compdef apt-get apt-cache apt-cdrom apt-config
_apt () {
case "${words[1]:t}" in
apt-get) _apt-get "$@";;
apt-cache) _apt-cache "$@";;
apt-cdrom) _apt-cdrom "$@";;
apt-config) _apt-config "$@";;
*) _message "unknown command $words[1]";;
esac
}
# usage: _apt_arguments funcname option-spec... -- rest-regex
_apt_arguments () {
local funcname
funcname="$1"
shift
typeset -A canonicalize num_options
local short_hasarg short_bool short_intlevel short_configfile short_arbitem
local long_hasarg long_bool long_intlevel long_configfile long_arbitem
local comp_hasarg=''
local opt opts type
while [[ 0 -lt $# && $1 != -- ]]; do
opts="${1%%:*}"
type="${1#*:}"
case $type in
bool) num_options[$opts]=1;;
intlevel) num_options[$opts]=-1;;
configfile) num_options[$opts]=1;;
arbitem) num_options[$opts]=-1;;
*) num_options[$opts]=1
comp_hasarg="${comp_hasarg}$opts) $type;;"$'\n'
type=hasarg;;
esac
for opt in ${(s:,:)=opts}; do
canonicalize[$opt]="$opts"
case $opt in
--*) eval "long_$type=(\$long_$type ${opt#--})";;
-?) eval "short_$type=(\$short_$type ${opt#-})";;
esac
done
shift
done
# skip --
[[ 0 -lt $# ]] && shift
comp_hasarg="{case \$current_option in
${comp_hasarg}esac}"
local short_seq false true bool bool_prefix intlevel word word1 nul qnul match
local comp_bool comp_intlevel comp_configfile comp_arbitem comp_long comp_opt
local regex_short regex_long regex_all
regex_all=( \( "$@" \) )
short_seq="(${(j:|:)short_bool}|${(j:|:)short_intlevel})#"
false=(no false without off disable)
true=(yes true with on enable)
bool=($false $true)
bool_prefix=(--${^bool}-)
intlevel='[0-9]##'
word=$'[^\0]#\0'
word1=$'[^\0]##\0'
nul=$'\0'
qnul="\$'\\0'"
comp_bool="($bool)"
comp_intlevel=
comp_configfile='_files'
comp_arbitem=
comp_short=\
'{if [[ $PREFIX = -'"$short_seq"' ]]; then
_apt_consume_short ${PREFIX[2,-1]}
tmp1=(${(M)${(s:,:)${(kj:,:)num_options[(R)*~0]}}:#-?})
tmp2=(${PREFIX}${^tmp1#-})
_describe -o option tmp1 tmp2
elif [[ -z "$PREFIX" ]]; then
tmp1=(${(M)${(s:,:)${(kj:,:)num_options[(R)*~0]}}:#-?})
_describe -o option tmp1
fi}'
comp_long=\
'tmp1="${(j:|:)${(@)${(@M)${(@s:,:)${(@kj:,:)num_options[(R)*~0]}}:#--*}#--}}"
tmp2=(--${(M)^long_bool:#$~tmp1} --${(M)^long_intlevel:#$~tmp1})
tmp3=(--${(M)^long_hasarg:#$~tmp1} --${(M)^long_configfile:#$~tmp1} --${(M)^long_arbitem:#$~tmp1})
_describe -o option tmp2 -- tmp3 -S= -- bool_prefix -S ""'
comp_long_prefix=\
'tmp1="${(j:|:)${(@)${(@M)${(@s:,:)${(@kj:,:)num_options[(R)*~0]}}:#--*}#--}}"
tmp2=($_ra_left${(M)^long_bool:#$~tmp1} $_ra_left${(M)^long_intlevel:#$~tmp1})
tmp3=($_ra_left${(M)^long_hasarg:#$~tmp1} $_ra_left${(M)^long_configfile:#$~tmp1} $_ra_left${(M)^long_arbitem:#$~tmp1})
tmp1="${(j:|:)${(@)${(@M)${(@s:,:)${(@kj:,:)num_options[(R)*~0]}}:#-?}#-}}"
tmp2=("$tmp2[@]" $_ra_left${(M)^short_bool:#$~tmp1} $_ra_left${(M)^short_intlevel:#$~tmp1})
tmp3=("$tmp3[@]" $_ra_left${(M)^short_hasarg:#$~tmp1} $_ra_left${(M)^short_configfile:#$~tmp1} $_ra_left${(M)^short_arbitem:#$~tmp1})
_describe -o option tmp2 -- tmp3 -S='
comp_opt='{{ ! zstyle -T ":completion:${curcontext}:options" prefix-needed || [[ "$PREFIX" = -* ]] }'" && { $comp_short; $comp_long }}"
comp_short="{$comp_short}"
comp_long="{$comp_long}"
regex_short=()
regex_long=()
regex_long_prefix=()
if (( $#short_hasarg )); then
regex_short=("$regex_short[@]"
/"$short_seq(${(j:|:)short_hasarg})(=|)"/
-'_apt_consume_short ${match[1]%=}; current_option=${canonicalize[-${${match[1]%=}[-1]}]}'
\( /"$word1"/ ":options:option:$comp_hasarg" \| /"$nul"/ /"$word"/ ":options:option:$comp_hasarg" \) \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)short_hasarg})$nul"/
-'_apt_consume_short ${match[1][-2]}; current_option=${canonicalize[-${${match[1]%'$qnul'}[-1]}]}'
/"$word"/ ":options:option:$comp_hasarg" \|
/"(${(j:|:)short_hasarg})="/
-'_apt_consume_short ${match[1][-2]}; current_option=${canonicalize[-${${match[1]%=}[-1]}]}'
\( /"$word1"/ ":options:option:$comp_hasarg" \| /"$nul"/ /"$word"/ ":options:option:$comp_hasarg" \) \|
)
fi
if (( $#short_bool )); then
regex_short=("$regex_short[@]"
/"$short_seq(${(j:|:)short_bool})($nul(${(j:|:)bool})|(${(j:|:)bool})|)$nul"/
-'_apt_consume_short ${match[1]%%('$qnul'('${(j:|:)bool}')|('${(j:|:)bool}')|)'$qnul'}' \|
/"$short_seq(${(j:|:)short_bool})="/
-'_apt_consume_short ${match[1]%=}'
\( /"$word1"/ ":names:boolean value:$comp_bool" \| /"$nul"/ /"$word"/ ":names:boolean value:$comp_bool" \) \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)short_bool})="/
-'_apt_consume_short ${match[1][-2]}'
\( /"$word1"/ ":names:boolean value:$comp_bool" \| /"$nul"/ /"$word"/ ":names:boolean value:$comp_bool" \) \|
/"(${(j:|:)short_bool})$nul"/
-'_apt_consume_short ${match[1][-2]}'
/"((${(j:|:)bool})$nul|)"/ ":names:boolean value:$comp_bool" \|
)
fi
if (( $#short_intlevel )); then
regex_short=("$regex_short[@]"
/"$short_seq(${(j:|:)short_intlevel})($nul$intlevel|$intlevel|)$nul"/
-'_apt_consume_short ${match[1]%%'"($qnul$intlevel|$intlevel|)$qnul"'}' \|
/"$short_seq(${(j:|:)short_intlevel})="/
-'_apt_consume_short ${match[1]%=}'
\( /"$word1"/ ":options:option:$comp_intlevel" \| /"$nul"/ /"$word"/ ":options:option:$comp_intlevel" \) \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)short_intlevel})="/
-'_apt_consume_short ${match[1][-2]}'
\( /"$word1"/ ":options:option:$comp_intlevel" \| /"$nul"/ /"$word"/ ":options:option:$comp_intlevel" \) \|
/"(${(j:|:)short_intlevel})$nul"/
-'_apt_consume_short ${match[1][-2]}'
/"($intlevel$nul|)"/ ":options:option:$comp_intlevel" \|
)
fi
if (( $#short_configfile )); then
regex_short=("$regex_short[@]"
/"$short_seq(${(j:|:)short_configfile})(=|)"/
-'_apt_consume_short ${match[1]%=}'
\( /"$word1"/ ":files:config file:$comp_configfile" \| /"$nul"/ /"$word"/ ":files:config file:$comp_configfile" \) \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)short_configfile})$nul"/
-'_apt_consume_short ${match[1][-2]}'
/"$word"/ ":files:config file:$comp_configfile" \|
/"(${(j:|:)short_configfile})="/
-'_apt_consume_short ${match[1][-2]}'
\( /"$word1"/ ":files:config file:$comp_configfile" \| /"$nul"/ /"$word"/ ":files:config file:$comp_configfile" \) \|
)
fi
if (( $#short_arbitem )); then
regex_short=("$regex_short[@]"
/"$short_seq(${(j:|:)short_arbitem})(=|)"/
-'_apt_consume_short ${match[1]%=}'
\( /"$word1"/ ":options:option:$comp_arbitem" \| /"$nul"/ /"$word"/ ":options:option:$comp_arbitem" \) \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)short_arbitem})$nul"/
-'_apt_consume_short ${match[1][-2]}'
/"$word"/ ":options:option:$comp_arbitem" \|
/"(${(j:|:)short_arbitem})="/
-'_apt_consume_short ${match[1][-2]}'
\( /"$word1"/ ":options:option:$comp_arbitem" \| /"$nul"/ /"$word"/ ":options:option:$comp_arbitem" \) \|
)
fi
if (( $#long_hasarg )); then
regex_long=("$regex_long[@]"
/"(${(j:|:)long_hasarg})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}; current_option=${canonicalize[--${match[1]%'$qnul'}]}'
/"$word"/ ":options:option:$comp_hasarg" \|
/"(${(j:|:)long_hasarg})="/
-'_apt_consume_long ${match[1]%=}; current_option=${canonicalize[--${match[1]%=}]}'
\( /"$word1"/ ":options:option:$comp_hasarg" \| /"$nul"/ /"$word"/ ":options:option:$comp_hasarg" \) \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)long_hasarg})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}; current_option=${canonicalize[--${match[1]%'$qnul'}]}'
/"$word"/ ":options:option:$comp_hasarg" \|
/"(${(j:|:)long_hasarg})="/
-'_apt_consume_long ${match[1]%=}; current_option=${canonicalize[--${match[1]%=}]}'
\( /"$word1"/ ":options:option:$comp_hasarg" \| /"$nul"/ /"$word"/ ":options:option:$comp_hasarg" \) \|
)
fi
if (( $#long_bool )); then
regex_long=("$regex_long[@]"
/"(${(j:|:)long_bool})="/
-'_apt_consume_long ${match[1]%=}'
\( /"$word1"/ ":names:boolean value:$comp_bool" \| /"$nul"/ /"$word"/ ":names:boolean value:$comp_bool" \) \|
/"(${(j:|:)long_bool})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}'
/"((${(j:|:)bool})$nul|)"/ ":names:boolean value:$comp_bool" \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)long_bool})="/
-'_apt_consume_long ${match[1]%=}'
\( /"$word1"/ ":names:boolean value:$comp_bool" \| /"$nul"/ /"$word"/ ":names:boolean value:$comp_bool" \) \|
/"(${(j:|:)long_bool})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}'
/"((${(j:|:)bool})$nul|)"/ ":names:boolean value:$comp_bool" \|
)
fi
if (( $#long_intlevel )); then
regex_long=("$regex_long[@]"
/"(${(j:|:)long_intlevel})="/
-'_apt_consume_long ${match[1]%=}'
\( /"$word1"/ ":options:option:$comp_intlevel" \| /"$nul"/ /"$word"/ ":options:option:$comp_intlevel" \) \|
/"(${(j:|:)long_intlevel})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}'
/"($intlevel$nul|)"/ ":options:option:$comp_intlevel" \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)long_intlevel})="/
-'_apt_consume_long ${match[1]%=}'
\( /"$word1"/ ":options:option:$comp_intlevel" \| /"$nul"/ /"$word"/ ":options:option:$comp_intlevel" \) \|
/"(${(j:|:)long_intlevel})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}'
/"($intlevel$nul|)"/ ":options:option:$comp_intlevel" \|
)
fi
if (( $#long_configfile )); then
regex_long=("$regex_long[@]"
/"(${(j:|:)long_configfile})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}'
/"$word"/ ":files:config file:$comp_configfile" \|
/"(${(j:|:)long_configfile})="/
-'_apt_consume_long ${match[1]%=}'
\( /"$word1"/ ":files:config file:$comp_configfile" \| /"$nul"/ /"$word"/ ":files:config file:$comp_configfile" \) \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)long_configfile})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}'
/"$word"/ ":files:config file:$comp_configfile" \|
/"(${(j:|:)long_configfile})="/
-'_apt_consume_long ${match[1]%=}'
\( /"$word1"/ ":files:config file:$comp_configfile" \| /"$nul"/ /"$word"/ ":files:config file:$comp_configfile" \) \|
)
fi
if (( $#long_arbitem )); then
regex_long=("$regex_long[@]"
/"(${(j:|:)long_arbitem})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}'
/"$word"/ ":options:option:$comp_arbitem" \|
/"(${(j:|:)long_arbitem})="/
-'_apt_consume_long ${match[1]%=}'
\( /"$word1"/ ":options:option:$comp_arbitem" \| /"$nul"/ /"$word"/ ":options:option:$comp_arbitem" \) \|
)
regex_long_prefix=("$regex_long_prefix[@]"
/"(${(j:|:)long_arbitem})$nul"/
-'_apt_consume_long ${match[1]%'$qnul'}'
/"$word"/ ":options:option:$comp_arbitem" \|
/"(${(j:|:)long_arbitem})="/
-'_apt_consume_long ${match[1]%=}'
\( /"$word1"/ ":options:option:$comp_arbitem" \| /"$nul"/ /"$word"/ ":options:option:$comp_arbitem" \) \|
)
fi
regex_all=(
/"$word"/
\( /--/+ \( "$regex_long[@]"
/"(${(j:|:)bool})-"/+
\( "$regex_long_prefix[@]"
/"[]"/ ":options:option:$comp_long_prefix" \) \) \|
/-/+ \( "$regex_short[@]" /"[]"/ \) \|
/"[]"/ ":options:option:$comp_opt" \) \#
"$regex_all[@]"
)
_regex_arguments "${funcname}_sm" "$regex_all[@]"
eval "$funcname () {
typeset -A canonicalize num_options
canonicalize=(${(kv)canonicalize})
num_options=(${(kv)num_options})
local short_hasarg short_bool short_intlevel short_configfile short_arbitem
local long_hasarg long_bool long_intlevel long_configfile long_arbitem
local bool_prefix
short_hasarg=($short_hasarg)
short_bool=($short_bool)
short_intlevel=($short_intlevel)
short_configfile=($short_configfile)
short_arbitem=($short_arbitem)
long_hasarg=($long_hasarg)
long_bool=($long_bool)
long_intlevel=($long_intlevel)
long_configfile=($long_configfile)
long_arbitem=($long_arbitem)
bool_prefix=($bool_prefix)
local current_option tmp1 tmp2 tmp3
${funcname}_sm
}"
}
_apt_consume_short () {
local short opt
for short in ${(s::)1}; do
opt="$canonicalize[-$short]"
(( 0 < num_options[$opt] && num_options[$opt]-- ))
done
return 0
}
_apt_consume_long () {
local long opt
opt="$canonicalize[--$1]"
(( 0 < num_options[$opt] && num_options[$opt]-- ))
return 0
}
_apt-get () {
_apt_arguments _apt-get_sm \
-h,--help:bool \
-v,--version:bool \
-q,--quiet,--silent:intlevel \
-d,--download-only:bool \
-b,--compile,--build:bool \
-s,--simulate,--just-print,--recon,--no-act:bool \
-y,--yes,--assume-yes:bool \
-f,--fix-broken:bool \
-u,--show-upgraded:bool \
-m,--ignore-missing,--fix-missing:bool \
--no-download:bool \
--ignore-hold:bool \
--no-upgrade:bool \
--force-yes:bool \
--print-uris:bool \
--purge:bool \
--list-cleanup:bool \
-c,--config-file:configfile \
-o,--option:arbitem \
-- \
/$'update\0'/ \| \
/$'upgrade\0'/ \| \
/$'install\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" uninstalled || _deb_packages "$expl_packages[@]" installed' \# \| \
/$'remove\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" installed' \# \| \
/$'dist-upgrade\0'/ \| \
/$'dselect-upgrade\0'/ \| \
/$'clean\0'/ \| \
/$'autoclean\0'/ \| \
/$'check\0'/ \| \
/$'source\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \| \
/$'help\0/' \| \
/"[]"/ ':argument-1::compadd "$expl_action[@]" update upgrade install remove dist-upgrade dselect-upgrade clean autoclean check source help'
_apt-get () {
local expl_action expl_packages
_description actions expl_action 'action'
_description packages expl_packages 'package'
_apt-get_sm
}
_apt-get "$@"
}
_apt-cache () {
_apt_arguments _apt-cache_sm \
-h,--help:bool \
-v,--version:bool \
-p,--pkg-cache:'_files "$expl_pkg_cache[@]"' \
-s,--src-cache:'_files "$expl_src_cache[@]"' \
-q,--quiet:intlevel \
-i,--important:bool \
-f,--full:bool \
--name-only:bool \
-c,--config-file:configfile \
-o,--option:arbitem \
-- \
/$'help\0'/ \| \
/$'add\0'/ /$'[^\0]#\0'/ ':files:index files:_files "$expl[@]"' \# \| \
/$'gencaches\0'/ \| \
/$'showpkg\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \| \
/$'stats\0'=$status[4]/ \| \
/$'dump\0'/ \| \
/$'dumpavail\0'/ \| \
/$'unmet\0'/ \| \
/$'check\0'/ \| \
/$'search\0'/ /$'[^\0]#\0'/ ':strings::_message "pattern"' \| \
/$'show\0'/ /$'[^\0]#\0'/ ':packages::_deb_packages "$expl_packages[@]" avail' \# \| \
/$'depends\0'/ \| \
/"[]"/ ':argument-1::compadd "$expl_action[@]" help add gencaches showpkg stats dump dumpavail unmet check search show depends'
_apt-cache () {
local expl_action expl_packages expl_pkg_cache expl_src_cache
_description actions expl_action 'action'
_description packages expl_packages 'package'
_description files expl_pkg_cache 'package cache'
_description files expl_src_cache 'source cache'
_apt-cache_sm
}
_apt-cache "$@"
}
_apt-cdrom () {
_apt_arguments _apt-cdrom_sm \
-h,--help:bool \
-v,--version:bool \
-d,--cdrom:'_files "$expl_mount_point[@]" -/' \
-r,--rename:bool \
-m,--no-mount:bool \
-f,--fast:bool \
-n,--just-print,--recon,--no-act:bool \
-a,--thorough:bool \
-c,--config-file:configfile \
-o,--option:arbitem \
-- \
/$'add\0'/ \| \
/"[]"/ ':argument-1::compadd "$expl_action[@]" add'
_apt-cdrom () {
local expl_action expl_mount_point
_description actions expl_action 'action'
_description files expl_mount_point 'mount point'
_apt-cdrom_sm
}
_apt-cdrom "$@"
}
_apt-config () {
_apt_arguments _apt-config \
-h,--help:bool \
-v,--version:bool \
-c,--config-file:configfile \
-o,--option:arbitem \
-- \
/$'shell\0'/ \
\( \
/$'[^\0]#\0'/ ':parameters:shell variable to assign:compadd "$expl[@]" - "${(@k)parameters}"' \
/$'[^\0]#\0'/ ':values:configuration key:compadd "$expl[@]" - ${${(f)"$(apt-config dump 2>&1)"}% *}' \
\) \# \| \
/$'dump\0'/ \| \
/"[]"/ ':argument-1:action:compadd "$expl[@]" shell dump'
_apt-config "$@"
}
_apt "$@"