aboutsummaryrefslogtreecommitdiff
blob: 61e04a0808ad0894485d2f5bd48e844def72311f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

# bash command-line completion for eselect
# Author: Aaron Walker <ka0ttic@gentoo.org>

_eselect() {
    local cur sedcmd possibles
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    sedcmd='s/^  \([[:alnum:]-][[:alnum:]_-]*\)[[:space:],].*$/\1/p'

    set - "${COMP_WORDS[@]:1}"
    while [[ $# -gt 1 && $1 == -* ]]; do
        shift
    done

    case $# in
        1) possibles=$(eselect help 2>/dev/null \
            | sed -n -e "${sedcmd}") ;;
        2) possibles=$(eselect "$1" usage 2>/dev/null \
            | sed -n -e "${sedcmd}") ;;
    esac

    [[ -n "${possibles}" ]] && \
        COMPREPLY=( $(compgen -W "${possibles}" -- ${cur}) )

    return 0
}

complete -F _eselect eselect

# Local Variables:
# mode: sh
# indent-tabs-mode: nil
# End:

# vim: set ft=sh tw=80 sw=4 et :