-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathpinctrl-completion.bash
More file actions
82 lines (76 loc) · 2.68 KB
/
pinctrl-completion.bash
File metadata and controls
82 lines (76 loc) · 2.68 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
_pinctrl ()
{
local cur prev words cword split cmd pins pincomp ALLPINS CHIPS chip pinmode=false prefix arg i func pull;
local opts="no op ip a0 a1 a2 a3 a4 a5 a6 a7 a8 dh dl pu pd pn ";
_init_completion -s || return;
i=1
while [[ $i -lt $cword && ${COMP_WORDS[$i]} =~ ^- ]]; do
arg=${COMP_WORDS[$i]}
if [[ "$arg" == "-c" ]]; then
chip=${COMP_WORDS[$((i + 1))]}
i=$((i + 2))
else
if [[ "$arg" == "-p" ]]; then
pinmode=true
fi
i=$((i + 1))
fi
done
if [[ $i -lt $cword && ${COMP_WORDS[$i]} =~ ^(get|set|funcs|poll|help) ]]; then
cmd=${COMP_WORDS[$i]}
i=$((i + 1))
elif [[ ${COMP_WORDS[$i]} =~ ^[A-Z0-9] ]]; then
cmd="set"
fi
if [[ "$cmd" != "" && $i -lt $cword ]]; then
pins=${COMP_WORDS[$i]};
i=$((i + 1))
while [[ $i -lt $cword && ${COMP_WORDS[$i]} =~ ^[-,] ]]; do
pins="$pins${COMP_WORDS[$i]}"
i=$((i + 1))
done
fi
if [[ "$pins" != "" ]]; then
while [[ $i -lt $cword ]]; do
arg=${COMP_WORDS[$i]}
if [[ $arg =~ ^(no|ip|op|a[0-8])$ ]]; then
func=$arg
opts=$(echo "$opts" | sed -E "s/(no|ip|op|a[0-8]) //g")
if [[ $func != "op" ]]; then
opts=$(echo "$opts" | sed -E "s/(dh|dl) //g")
fi
elif [[ $arg =~ ^(pu|pd|pn)$ ]]; then
pull=$arg
opts=$(echo "$opts" | sed -E "s/(pu|pd|pn) //g")
fi
i=$((i + 1))
done
fi
if [[ "$cmd" != "" && ( "$pins" == "" || "${cur}" =~ [-,] ) ]]; then
prefix=$(echo $cur | sed 's/[^-,]*$//')
if $pinmode; then
ALLPINS={1..40}
else
ALLPINS=($(pinctrl get | cut -d'/' -f4 | cut -d' ' -f1) $(pinctrl get | cut -d'/' -f3 | cut -d' ' -f2))
fi
pincomp="${ALLPINS[@]/#/$prefix}"
COMPREPLY+=($(compgen -W "$pincomp" -- $cur))
elif [[ "$cmd" != "" ]]; then
if [[ "$cmd" == "set" ]]; then
COMPREPLY+=($(compgen -W "$opts" -- $cur))
fi
else
if [[ "$prev" == "-c" ]]; then
CHIPS=($(pinctrl -v -p 0 | grep 'gpios)' | cut -d' ' -f4 | sort | uniq))
chips="${CHIPS[@]}"
COMPREPLY+=($(compgen -W "$chips" -- $cur))
elif [[ "$cur" =~ ^- ]]; then
COMPREPLY+=($(compgen -W "-p -h -v -c" -- $cur))
elif [[ "$chip" == "" ]]; then
COMPREPLY+=($(compgen -W "get set poll funcs help" -- $cur))
else
COMPREPLY+=($(compgen -W "funcs help" -- $cur))
fi
fi
}
complete -F _pinctrl pinctrl