aboutsummaryrefslogtreecommitdiff
blob: 82730d37e671ae49d76a94b69a3183469cdda75c (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
# Copyright 1999-2005 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 prev preprev sedcmd possibles
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    sedcmd='sed -n -e s/^[[:space:]]\+.*1m\([^[:space:]][[:alnum:]-]\+\).*[[:space:]]\+.*$/\1/p'
    opts="--no-colour"

    if [[ ${COMP_CWORD} -eq 1 ]] || [[ -n "${prev}" && ${prev} == -* ]]
    then
        possibles="$(eselect list-modules | ${sedcmd}) ${opts}"
    elif eselect ${prev} usage &>/dev/null ; then
        possibles=$(eselect ${prev} usage | ${sedcmd})
    fi

    [[ -n "${possibles}" ]] && \
        COMPREPLY=($(compgen -W "${possibles}" -- ${cur}))
    return 0
}
complete -F _eselect eselect

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