summaryrefslogtreecommitdiff
path: root/src/bashrc/pcp_completion.sh
blob: fe0ce82a1672fe7a29e0716cdb3c9a046506791f (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
# Programmable completion for Performance Co-Pilot commands under bash.
# Author:  Roman Revyakin (Roman), rrevyakin@aconex.com

_pminfo_complete ()
{
    local cur=${COMP_WORDS[$COMP_CWORD]}
    local opt_regex= curpos_expand=

    COMPREPLY=() 

    # Options that need no completion and the cursor position to start
    # expansion from for different programs  
    case ${COMP_WORDS[0]} in
        pminfo) 
        opt_regex="-[abhnOZ]"
        curpos_expand=1
        ;;

        pmprobe) 
        opt_regex="-[ahnOZ]"
        curpos_expand=1
        ;;

        pmdumptext) 
        opt_regex="-[AacdfhnOPRsStTUwZ]"
        curpos_expand=1
        ;;

        pmdumplog) 
        opt_regex="-[nSTZ]"
        curpos_expand=1
        ;;

        pmlogsummary) 
        opt_regex="-[BnpSTZ]"
        curpos_expand=2
        ;;

        pmstore) 
        opt_regex="-[hin]"
        curpos_expand=1
        ;;

        pmval) 
        opt_regex="-[AafhinOpSsTtwZ]"
        curpos_expand=1
        ;;

        pmevent) 
        opt_regex="-[ahKOpSsTtZ]"
        curpos_expand=1
        ;;

    esac    # --- end of case ---

    # We expand either straight from the cursor if it is at the position to
    # expand or check for the preceding options whether to expand or not 
    if (( $COMP_CWORD == $curpos_expand )) || \
        ( (( $COMP_CWORD > $curpos_expand )) \
            && ! [[ "${COMP_WORDS[$((COMP_CWORD-1))]}" =~ $opt_regex ]] 
        )
    then
        COMPREPLY=(`compgen -W '$(command pminfo)' 2>/dev/null $cur`)
    fi 

}    # ----------  end of function _pminfo_complete  ----------

complete -F _pminfo_complete -o default pminfo pmprobe pmdumptext pmdumplog pmlogsummary pmstore pmval pmevent