forked from dfu-programmer/dfu-programmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfu_completion
132 lines (117 loc) · 4.39 KB
/
dfu_completion
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# dfu_completion file, partial of dfu_programmer script
TARGETS=$( echo $TARGET_INFO | sed 's/::[xX0-9A-Fa-f]*//g' )
COMMANDS=(launch read erase flash setsecure config get getfuse setfuse hex2bin bin2hex)
_dfu-programmer () {
local i filetype
local cur cmd prev target
local flags
local eeprom_size
export cur=${COMP_WORDS[COMP_CWORD]}
export target=${COMP_WORDS[1]}
export cmd=${COMP_WORDS[2]}
export prev=${COMP_WORDS[COMP_CWORD - 1]}
COMPREPLY=() # Array variable storing the possible completions.
if [[ "$COMP_CWORD" == "1" ]]; then
COMPREPLY=( $( compgen -W "$TARGETS" -- $cur ) )
fi
if [[ "$COMP_CWORD" == "2" ]]; then
COMPREPLY=( $( compgen -W "${COMMANDS[*]}" -- $cur ) )
fi
if [[ "$COMP_CWORD" > "2" ]]; then
case "$cmd" in
hex2bin)
filetype="hex"
if [[ $filetype != none ]]; then
#COMPREPLY+=( $( compgen -f -X "!*.$filetype" -- $cur ) )
COMPREPLY+=( $( compgen -o plusdirs -f -X "!*.$filetype" -- $cur ) )
fi
# make sure there isn't a trailing space for directories
if [[ ${#COMPREPLY[@]} == 1 ]]; then
if [[ -d ${COMPREPLY[0]} ]]; then
COMPREPLY[0]=$( echo ${COMPREPLY[0]} | sed 's/$/\//' )
# If there's only one option, without =, then allow a space
compopt -o nospace
fi
if [[ ${COMPREPLY[0]} == "--"*"=" ]]; then
compopt -o nospace
fi
fi
;;
bin2hex)
;;
launch)
if [[ "$COMP_CWORD" == "3" ]]; then
COMPREPLY=( $( compgen -W '--no-reset' -- $cur ) )
fi
;;
read)
# only either user or eeprom should be displayed based on if device has
# either feature -- or either one is selected when both features exist
flags="--force --user --eeprom --bin"
eeprom_size=$( echo $TARGET_INFO | sed "s/.* $target:://" | sed 's/ .*//' )
if [[ "$eeprom_size" == 0 ]]; then
flags=$( echo $flags | sed 's/--eeprom//' )
fi
COMPREPLY=( $( compgen -W "$flags" -- $cur ) )
;;
erase)
COMPREPLY=( $( compgen -W '--force --suppress-validation' -- $cur ) )
;;
flash)
filetype="hex"
flags="--force --user --eeprom --bin --suppress-validation --suppress-bootloader-mem --validate-first --ignore-outside --serial="
eeprom_size=$( echo $TARGET_INFO | sed "s/.* $target:://" | sed 's/ .*//' )
if [[ "$eeprom_size" == 0 ]]; then
flags=$( echo $flags | sed 's/--eeprom//' )
fi
for (( i = 3; i < COMP_CWORD; i++ )); do
if [[ "${COMP_WORDS[i]}" == *.@(bin|hex) ]]; then
filetype="none"
flags=$( echo $flags | sed 's/--bin//' )
elif [[ "${COMP_WORDS[i]}" == --bin ]]; then
if [[ filetype != none ]]; then
filetype="bin"
fi
flags=$( echo $flags | sed 's/--bin//' )
elif [[ "${COMP_WORDS[i]}" == --@(user|eeprom) ]]; then
flags=$( echo $flags | sed 's/--user//' )
flags=$( echo $flags | sed 's/--eeprom//' )
else
flags=$( echo $flags | sed "s/${COMP_WORDS[i]}//" )
fi
done
COMPREPLY=( $( compgen -W "$flags" -- $cur ) )
if [[ $filetype != none ]]; then
#COMPREPLY+=( $( compgen -f -X "!*.$filetype" -- $cur ) )
COMPREPLY+=( $( compgen -o plusdirs -f -X "!*.$filetype" -- $cur ) )
fi
#if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != "--"*"=" ]] ; then
# make sure there isn't a trailing space for directories
if [[ ${#COMPREPLY[@]} == 1 ]]; then
if [[ -d ${COMPREPLY[0]} ]]; then
COMPREPLY[0]=$( echo ${COMPREPLY[0]} | sed 's/$/\//' )
# If there's only one option, without =, then allow a space
compopt -o nospace
fi
if [[ ${COMPREPLY[0]} == "--"*"=" ]]; then
compopt -o nospace
fi
fi
;;
setsecure)
;;
configure)
;;
get)
;;
getfuse)
COMPREPLY=( $( compgen -W 'LOCK EPFL BOOTPROT BODLEVEL BODHYST BODEN ISP_BOD_EN ISP_IO_COND_EN ISP_FORCE' -- $cur ) )
;;
setfuse)
COMPREPLY=( $( compgen -W 'LOCK EPFL BOOTPROT BODLEVEL BODHYST BODEN ISP_BOD_EN ISP_IO_COND_EN ISP_FORCE' -- $cur ) )
;;
esac
fi
return 0
}
complete -F _dfu-programmer dfu-programmer