summaryrefslogtreecommitdiffstats
path: root/completions/info
blob: 3a135650f051d8794aab5c05d3f79c2e8b2a356f (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# bash completion for info                                 -*- shell-script -*-

_comp_cmd_info()
{
    local cur prev words cword was_split comp_args
    _comp_initialize -s -- "$@" || return

    # default completion if parameter looks like a path
    if [[ $cur == @(*/|[.~])* ]]; then
        _comp_compgen_filedir
        return
    fi

    local noargopts='!(-*|*[kndfor]*)'
    # shellcheck disable=SC2254
    case $prev in
        --apropos | --index-search | --node | --help | --version | -${noargopts}[knhv])
            return
            ;;
        -${noargopts}d)
            if [[ ${1##*/} == info ]]; then
                _comp_compgen_filedir -d
                return
            fi
            ;;
        --directory)
            _comp_compgen_filedir -d
            return
            ;;
        --dribble | --file | --output | --restore | --raw-filename | --rcfile | -${noargopts}[for])
            _comp_compgen_filedir
            return
            ;;
    esac

    [[ $was_split ]] && return

    if [[ $cur == -* ]]; then
        _comp_compgen_help
        [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
        return
    fi

    local i infopath=/usr/share/info

    if [[ ${INFOPATH-} == *: ]]; then
        infopath=${INFOPATH}${infopath}
    elif [[ ${INFOPATH:+set} ]]; then
        infopath=$INFOPATH
    fi

    _comp_split -F : infopath "$infopath"
    if ((${#infopath[@]})); then
        _comp_compgen -Rv infopath -- -S "/$cur*" -W '"${infopath[@]}"'
        local IFS=
        if _comp_expand_glob COMPREPLY '${infopath[@]}'; then
            # weed out directory path names and paths to info pages (empty
            # elements will be removed by the later `compgen -X ''`)
            COMPREPLY=("${COMPREPLY[@]##*/?(:)}")
            # strip suffix from info pages
            COMPREPLY=("${COMPREPLY[@]%.@(gz|bz2|xz|lzma)}")
            # weed out info dir file with -X 'dir'
            _comp_compgen -c "${cur//\\\\/}" -- -W '"${COMPREPLY[@]%.*}"' -X '@(|dir)'
        fi
        _comp_unlocal IFS
    fi
} &&
    complete -F _comp_cmd_info info pinfo

# ex: filetype=sh