diff options
author | Thomas Deutschmann <whissi@gentoo.org> | 2019-07-14 18:07:29 +0200 |
---|---|---|
committer | Thomas Deutschmann <whissi@gentoo.org> | 2019-07-14 20:57:03 +0200 |
commit | e9c8d7682c15d9ca298a3c86f00726f4ada4bab3 (patch) | |
tree | 2bb04c88f4dcccb2cc47544f4b66a7b1b149f940 /sys-kernel/genkernel/files | |
parent | dev-lang/lazarus: remove old 1.6.4, 1.8.4 (diff) | |
download | gentoo-e9c8d7682c15d9ca298a3c86f00726f4ada4bab3.tar.gz gentoo-e9c8d7682c15d9ca298a3c86f00726f4ada4bab3.tar.bz2 gentoo-e9c8d7682c15d9ca298a3c86f00726f4ada4bab3.zip |
sys-kernel/genkernel: update ebuild for genkernel v4
Package-Manager: Portage-2.3.68, Repoman-2.3.16
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'sys-kernel/genkernel/files')
-rw-r--r-- | sys-kernel/genkernel/files/genkernel-4.bash | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/sys-kernel/genkernel/files/genkernel-4.bash b/sys-kernel/genkernel/files/genkernel-4.bash new file mode 100644 index 000000000000..631fc8b30e47 --- /dev/null +++ b/sys-kernel/genkernel/files/genkernel-4.bash @@ -0,0 +1,74 @@ +# genkernel (8) completion +# Copyright 1999-2019 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 +# Written by Aron Griffis <agriffis@gentoo.org> + +_genkernel() +{ + declare cur prev genkernel_help actions params + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + # extract initial list of params/actions from genkernel --help + genkernel_help=$(command genkernel --help) + actions=( $(<<<"$genkernel_help" sed -n \ + '/^Available Actions:/,/^$/s/^[[:space:]]\+\([^[:space:]]\+\).*/\1/p') ) + params=( $(<<<"$genkernel_help" egrep -oe '--[^[:space:]]{2,}') ) + + # attempt to complete the current parameter based on the list + COMPREPLY=($(compgen -W "${params[*]/=*/=} ${actions[*]}" -- "$cur")) + + # if we don't have a rhs to complete + if [[ ${#COMPREPLY[@]} -gt 1 ]]; then + return + elif [[ ${#COMPREPLY[@]} -eq 0 && $cur != --*=* ]]; then + return + elif [[ ${#COMPREPLY[@]} -eq 1 && $COMPREPLY != --*= ]]; then + # using nospace completion, add an explicit space + COMPREPLY="${COMPREPLY} " + return + fi + + # we have a unique lhs and need to complete the rhs + declare args lhs rhs + if [[ ${#COMPREPLY[@]} -eq 1 ]]; then + lhs=$COMPREPLY + else + lhs=${cur%%=*}= + rhs=${cur#*=} + fi + + # genkernel's help gives clues as to what belongs on the rhs. + # extract the clue for the current parameter + args=" ${params[*]} " + args="${args##* $lhs}" + args="${args%% *}" + + # generate a list of completions for the argument; this replaces args with + # an array of results + args=( $(case $args in + ('<0-5>') compgen -W "$(echo {1..5})" -- "$rhs" ;; + ('<outfile>'|'<file>') compgen -A file -o plusdirs -- "$rhs" ;; + ('<archive>') compgen -G '*.tar.xz' -G '*.tbz2' -G '*.tar.bz2' -o plusdirs -- "$rhs" ;; + ('<dir>'|'<path>') compgen -A directory -S / -- "$rhs" ;; + + (*) compgen -o bashdefault -- "$rhs" ;; # punt + esac) ) + + # we're using nospace completion to prevent spaces after paths that aren't + # "done" yet. So do some hacking to the args to add spaces after + # non-directories. + declare slash=/ + args=( "${args[@]/%/ }" ) # add space to all + args=( "${args[@]/%$slash /$slash}" ) # remove space from dirs + + # recreate COMPREPLY + if [[ $cur == "$lhs"* ]]; then + COMPREPLY=( "${args[@]}" ) + elif [[ ${#args[@]} -gt 0 ]]; then + COMPREPLY=( "${args[@]/#/$lhs}" ) + fi +} + +complete -o nospace -F _genkernel genkernel |