# -*- mode: sh; indent-tabs-mode: nil; -*- vim: set ft=sh tw=80 sw=4 et : # Copyright 2005-2023 Gentoo Authors # Distributed under the terms of the GNU GPL version 2 or later # bash command-line completion for eselect # Author: Aaron Walker # Maintainer: _eselect() { local cur sedcmd2 sedcmd3 possibles local options="--brief --color= --colour= --eprefix= --root=" COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" sedcmd2='s/^ \([[:alnum:]-][[:alnum:]_-]*\)[[:space:],].*$/\1/p' sedcmd3='s/^ \[[[:digit:]][[:digit:]]*\] *\([[:graph:]]*\).*$/\1/p' set -- "${COMP_WORDS[@]:1}" # skip global options while [[ $# -gt 1 && $1 == -* ]]; do [[ $2 == "=" ]] && shift 2 shift done # skip any subaction options while [[ $# -gt 3 && $3 == -* ]]; do set -- "${@:1:2}" "${@:4}" done case $# in 0|1) possibles="${options} $(eselect modules list --only-names \ 2>/dev/null)" ;; 2) possibles=$(eselect --brief "$1" usage 2>/dev/null \ | sed -n -e "${sedcmd2}") ;; 3) case $2 in set|enable|disable) possibles=$(eselect "$1" list 2>/dev/null \ | sed -n -e "${sedcmd3}") ;; esac ;; esac if [[ -n "${possibles}" ]]; then COMPREPLY=( $(compgen -W "${possibles}" -- ${cur}) ) [[ ${COMPREPLY[0]} == *= ]] && compopt -o nospace fi return 0 } complete -F _eselect eselect