diff options
author | Felix Neumärker <xdch47@posteo.de> | 2020-02-19 17:44:18 +0100 |
---|---|---|
committer | Vadim Misbakh-Soloviov <mva@gentoo.org> | 2020-02-20 01:50:56 +0700 |
commit | 8a1dcc8e862e1ca00fec39f921bcd2d9cf55c0e7 (patch) | |
tree | 7dda7a7437ae4a58e389e11fdb003612f48aa2ba | |
parent | Update portage-utils completion (diff) | |
download | zsh-completion-8a1dcc8e862e1ca00fec39f921bcd2d9cf55c0e7.tar.gz zsh-completion-8a1dcc8e862e1ca00fec39f921bcd2d9cf55c0e7.tar.bz2 zsh-completion-8a1dcc8e862e1ca00fec39f921bcd2d9cf55c0e7.zip |
Merge PR #22 (eselect fixes)
[PATCH 1/6] _eselect: php-module completion
[PATCH 2/6] _eselect: generic uses _describe instead of values
[PATCH 3/6] _ekeyword: inital completion
[PATCH 4/6] _eselect: news modules - fix order
[PATCH 5/6] _eselect: completion for rc module / rc-config
[PATCH 6/6] _eselect: repository fixes + options
Signed-off-by: Felix Neumärker <xdch47@posteo.de>
Signed-off-by: Vadim Misbakh-Soloviov <mva@gentoo.org>
-rw-r--r-- | src/_ekeyword | 23 | ||||
-rw-r--r-- | src/_eselect | 161 |
2 files changed, 139 insertions, 45 deletions
diff --git a/src/_ekeyword b/src/_ekeyword new file mode 100644 index 0000000..c86ebb0 --- /dev/null +++ b/src/_ekeyword @@ -0,0 +1,23 @@ +#compdef ekeyword + +local -a arguments=( + '(- :)'{-h,--help}'[Show this help message and exit]' + '(-m --manifest)'{-m,--manifest}'[Run `ebuild manifest` on the ebuild after modifying it]' + '(-n --dry-run)'{-n,--dry-run}'[Show what would be changed, but do not commit]' + '(-v --verbose)'{-v,--verbose}'[Be verbose while processing things]' + '(-q --quiet)'{-q,--quiet}'[Be quiet while processing things (only show errors)]' + '(--format)'--format':Select output format for showing differences:_values -V ekeywordsfmt "ekeywords formats" auto color-inline inline short-multi long-multi' + '(- :)'{-V,--version}'[Show version information]' +) + +(( $+functions[_ekeywordargs] )) || _ekeywordargs() { + _files -g \*.ebuild + + local -a keywords=(all $(_gentoo_arches)) + + compset -P '(\^|\~)' + _values -V "keywords" "gentoo arches" ${keywords[@]} +} + +_arguments ${arguments[@]} "*:ekeywordargs:_ekeywordargs" + diff --git a/src/_eselect b/src/_eselect index 77b9fd6..ce185a8 100644 --- a/src/_eselect +++ b/src/_eselect @@ -45,25 +45,24 @@ _eselect_parse_generic() { } _eselect_parse_action_list() { - local eselect_list - local idx descr - local arr_items_selected=$2 - local arr_items_unselected=$3 - - eselect_list="$(LANG=C COLUMNS=100 eselect --colour=no $1 list 2> /dev/null)" - while IFS="" read -r ele ; do - echo "$ele" | read idx descr - idx=${idx#*\[} - idx=${idx%\]*} - if [[ "$idx" =~ '^[0-9]+$' ]]; then - local stripped_descr="${descr% *\**}" - if [[ "${stripped_descr}" != "${descr}" ]] ; then - set -A $arr_items_selected ${(P)arr_items_selected} "$idx:${(q)descr}" - else - set -A $arr_items_unselected ${(P)arr_items_unselected} "$idx:${(q)descr}" - fi + local idx item tag + local -a _sel_items + local -a _unsel_items + + while read idx item tag descr ; do + if [[ "$idx" == '[' && "$item" == ']' ]] ; then + continue + fi + if [[ ${tag} =~ '^[*@#]$' ]] ; then + _sel_items+=($item) + else + _unsel_items+=($item) fi - done <<< "$eselect_list" + done <<< $(LANG=C COLUMNS=100 eselect --colour=no $1 list 2> /dev/null | tail -n +2) + + set -A $2 ${_sel_items[@]} + set -A $3 ${_unsel_items[@]} + } _eselect_module_action() { @@ -78,9 +77,15 @@ _eselect_complete_action() { local actionname=$(_eselect_get_module) if (( $+functions[_eselect_complete_${actionname}_action] )) ; then _eselect_complete_${actionname}_action - else + return 0 + fi + + if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then _eselect_complete_action_generic ${actionname} + return 0 fi + + _nothing } _eselect_get_module() { @@ -110,31 +115,29 @@ _eselect_module() { _eselect_parse_generic } -_eselect_complete_action_generic() { +(( $+function[_eselect_complete_action_generic] )) || _eselect_complete_action_generic() { local -a sel_items local -a unsel_items - if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then - case "$(_eselect_get_action)" in - ("set"|"enable")) - _eselect_parse_action_list $1 sel_items unsel_items - if (( $#unsel_items + $#sel_items > 0 )) ; then - _describe -t eselect_sel -V 'eselect items' unsel_items - if (( $#unsel_items + $#sel_items < 10 )) ; then - _describe -t eselect_unsel -V 'eselect already selected items' sel_items - fi - return 0 - fi - ;; - ("remove"|"disable")) - _eselect_parse_action_list $1 sel_items unsel_items - if [[ -n "${sel_items[@]}" ]] ; then - _describe -V 'eselect items' sel_items - return 0 + case "$(_eselect_get_action)" in + ("set"|"enable")) + _eselect_parse_action_list $1 sel_items unsel_items + if (( $#unsel_items + $#sel_items > 0 )) ; then + _describe -t eselect_sel -V 'eselect items' unsel_items + if (( $#unsel_items + $#sel_items < 10 )) ; then + _describe -t eselect_unsel -V 'eselect already selected items' sel_items fi - ;; - esac - fi + return 0 + fi + ;; + ("remove"|"disable")) + _eselect_parse_action_list $1 sel_items unsel_items + if [[ -n "${sel_items[@]}" ]] ; then + _describe -V 'eselect items' sel_items + return 0 + fi + ;; + esac _nothing } @@ -145,15 +148,19 @@ _eselect_complete_action_generic() { case "$(_eselect_get_action)" in ("read"|"unread")) - local -a extra_items=('all:Read all news items') + local idx descr + while read idx descr ; do + idx=${idx#'['} + idx=${idx%']'} + items=(${idx}:${(q)descr} ${items[@]}) + done <<< $(eselect --colour=no news list 2> /dev/null | tail -n +2) + items+=('all:Read all news items') if [[ $(_eselect_get_action) == "read" ]] ; then - extra_items=('new:Read unread news items (default)' "${extra_items[@]}") + items+=('new:Read unread news items (default)') fi - _eselect_parse_action_list news items items - items=(${(q)extra_items[@]} ${(Oa)items}) if [[ -n "${items[@]}" ]] ; then - _describe -V 'eselect items' items + _describe -V 'eselect news' items return 0 fi ;; @@ -207,6 +214,70 @@ _eselect_complete_action_generic() { _nothing } +(( $+functions[_eselect_complete_php_action] )) || _eselect_complete_php_action() { + if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then + case "$(_eselect_get_action)" in + ("list"|"set"|"show"|"update")) + _values 'eselect php modules' $(eselect --colour=no --brief php list-modules) + return 0 + ;; + esac + elif (( $NORMARG + $(_eselect_action_index) + 1 == $CURRENT )) ; then + case "$words[$CURRENT-2]" in + "set") + local targets=($(eselect --colour=no --brief php list "$words[$CURRENT-1]" 2> /dev/null)) + if [ -n "$targets" ]; then + _values 'eselect php modules' ${targets[@]} + return 0 + fi + ;; + esac + fi + + _nothing +} + +(( $+functions[_eselect_complete_rc_action] )) || _eselect_complete_rc_action() { + if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then + case "$(_eselect_get_action)" in + ("list"|"show")) + _values 'runlevels' $(command ls --color=never ${EPREFIX}/etc/runlevels) + return 0 + ;; + ("add"|"delete"|"pause"|"reload"|"restart"|"start"|"stop")) + _values 'scripts' $(rc-service -l) + return 0 + ;; + esac + elif (( $NORMARG + $(_eselect_action_index) + 1 == $CURRENT )) ; then + case "$words[$CURRENT-2]" in + ("add"|"delete")) + _values 'runlevels' $(command ls --color=never ${EPREFIX}/etc/runlevels) + return 0 + ;; + esac + fi + + _nothing +} + + +(( $+functions[_eselect_complete_repository_action] )) || _eselect_complete_repository_action() { + local -a opts + + case "$(_eselect_get_action)" in + ("disable"|"remove")) + opts=('-f:Force potentially dangerous removals') + ;; + "list") + opts=('-i:Only list installed') + ;; + esac + + _describe -o 'options' opts + _eselect_complete_action_generic repository +} + eselect_comp() { integer NORMARG |