PageRenderTime 90ms CodeModel.GetById 88ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion_lib/complete -o filenames/info

http://github.com/brinkman83/bashrc
#! | 52 lines | 40 code | 12 blank | 0 comment | 0 complexity | 20c2391e071ae4638f3feb5db7552957 MD5 | raw file
 1# info(1) completion
 2
 3
 4comp_include _expand _filedir _get_cword
 5
 6
 7_info()
 8{
 9    local cur infopath UNAME
10
11    COMPREPLY=()
12    cur=`_get_cword`
13
14    _expand || return 0
15
16    # default completion if parameter contains /
17    if [[ "$cur" == */* ]]; then
18        _filedir
19        return 0
20    fi
21
22    infopath='/usr/share/info'
23
24    if [ "${INFOPATH: -1:1}" == ':' ]; then
25        infopath=${INFOPATH}${infopath}
26    elif [ ${INFOPATH:+set} ]; then
27        infopath=$INFOPATH
28    fi
29
30    infopath=$infopath:
31    if [ -n "$cur" ]; then
32        infopath="${infopath//://$cur* }"
33    else
34        infopath="${infopath//:// }"
35    fi
36
37    # redirect stderr for when path doesn't exist
38    COMPREPLY=( $( eval command ls "$infopath" 2>/dev/null ) )
39    # weed out directory path names and paths to info pages
40    COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
41    # weed out info dir file
42    for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do
43        if [ "${COMPREPLY[$i]}" == 'dir' ]; then
44            unset COMPREPLY[$i];
45        fi;
46    done  
47    # strip suffix from info pages
48    COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
49    COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
50
51    return 0
52} # _info()