PageRenderTime 146ms CodeModel.GetById 142ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/bash_completion_lib/complete/postcat

http://github.com/brinkman83/bashrc
#! | 42 lines | 37 code | 5 blank | 0 comment | 0 complexity | 3995a39e6fa2b83ebf7687028e390a8b MD5 | raw file
 1# postcat(1)
 2#
 3comp_include _filedir _get_cword
 4
 5
 6_postcat()
 7{
 8    local cur prev pval len idx qfile
 9
10    cur=`_get_cword`
11    prev=${COMP_WORDS[COMP_CWORD-1]}
12
13    if [[ $cur == '-' ]]; then
14        COMPREPLY=(-c -q -v)
15        return 0
16    fi
17    if [[ $prev == '-c' ]]; then
18        _filedir -d
19        return 0
20    fi
21
22    qfile=0
23    for idx in ${COMP_WORDS[@]}; do
24        [[ "$idx" = -q ]] && qfile=1 && break
25    done
26    if [[ $qfile == 1 ]]; then
27        len=${#cur}
28        idx=0
29        for pval in $( mailq | \
30            sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
31            if [[ "$cur" == "${pval:0:$len}" ]]; then
32                COMPREPLY[$idx]=$pval
33                idx=$(($idx+1))
34            fi
35        done
36        return 0
37    else
38        _filedir
39        return 0
40    fi
41}
42_postcat