bashrc: defend against unexpected bash completion input
[pcp.git] / src / bashrc / pcp_completion.sh
blob9bffae0ff36856354069336aee239f93e9d1cd68
1 # Programmable completion for Performance Co-Pilot commands under bash.
2 _pcp_complete()
4 local cur=${COMP_WORDS[$COMP_CWORD]}
5 local curpos_expand=0
6 local opt_regex=""
8 COMPREPLY=()
10 # Options that need no completion and the cursor position to start
11 # expansion from for different programs
12 case ${COMP_WORDS[0]} in
14 pmdumplog)
15 opt_regex="-[nSTZ]"
16 curpos_expand=1
19 pmdumptext)
20 opt_regex="-[AacdfhnOPRsStTUwZ]"
21 curpos_expand=1
24 pmevent)
25 opt_regex="-[AafhinOpSsTtwZ]"
26 curpos_expand=1
29 pminfo)
30 opt_regex="-[abhnOZ]"
31 curpos_expand=1
34 pmlogsummary)
35 opt_regex="-[BnpSTZ]"
36 curpos_expand=2
39 pmprobe)
40 opt_regex="-[ahnOZ]"
41 curpos_expand=1
44 pmrep)
45 opt_regex="-[AaBbcCdDeEfFGhHiKLloOpPqQrsStTuUVwxyYzZ]"
46 curpos_expand=1
49 pmstore)
50 opt_regex="-[hin]"
51 curpos_expand=1
54 pmval)
55 opt_regex="-[AafhinOpSsTtwZ]"
56 curpos_expand=1
59 esac # --- end of case ---
61 # We expand either straight from the cursor if it is at the position to
62 # expand or check for the preceding options whether to expand or not
63 if (( $COMP_CWORD == $curpos_expand )) || \
64 ( (( $COMP_CWORD > $curpos_expand )) \
65 && ! [[ "${COMP_WORDS[$((COMP_CWORD-1))]}" =~ $opt_regex ]]
67 then
68 COMPREPLY=(`compgen -W '$(command pminfo)' 2>/dev/null $cur`)
71 } # ---------- end of function _pcp_complete ----------
73 complete -F _pcp_complete -o default pmdumplog pmdumptext pmevent pminfo pmlogsummary pmprobe pmrep pmstore pmval