| 1 |
# dfu_completion file, partial of dfu_programmer script |
| 2 |
|
| 3 |
TARGETS=$( echo $TARGET_INFO | sed 's/::[xX0-9A-Fa-f]*//g' ) |
| 4 |
|
| 5 |
COMMANDS=(launch read erase flash setsecure config get getfuse setfuse hex2bin bin2hex) |
| 6 |
|
| 7 |
_dfu-programmer () { |
| 8 |
local i filetype |
| 9 |
local cur cmd prev target |
| 10 |
local flags |
| 11 |
local eeprom_size |
| 12 |
|
| 13 |
export cur=${COMP_WORDS[COMP_CWORD]} |
| 14 |
export target=${COMP_WORDS[1]} |
| 15 |
export cmd=${COMP_WORDS[2]} |
| 16 |
export prev=${COMP_WORDS[COMP_CWORD - 1]} |
| 17 |
|
| 18 |
COMPREPLY=() # Array variable storing the possible completions. |
| 19 |
|
| 20 |
if [[ "$COMP_CWORD" == "1" ]]; then |
| 21 |
COMPREPLY=( $( compgen -W "$TARGETS" -- $cur ) ) |
| 22 |
fi |
| 23 |
|
| 24 |
if [[ "$COMP_CWORD" == "2" ]]; then |
| 25 |
COMPREPLY=( $( compgen -W "${COMMANDS[*]}" -- $cur ) ) |
| 26 |
fi |
| 27 |
|
| 28 |
if [[ "$COMP_CWORD" > "2" ]]; then |
| 29 |
|
| 30 |
case "$cmd" in |
| 31 |
hex2bin) |
| 32 |
filetype="hex" |
| 33 |
|
| 34 |
if [[ $filetype != none ]]; then |
| 35 |
#COMPREPLY+=( $( compgen -f -X "!*.$filetype" -- $cur ) ) |
| 36 |
COMPREPLY+=( $( compgen -o plusdirs -f -X "!*.$filetype" -- $cur ) ) |
| 37 |
fi |
| 38 |
|
| 39 |
# make sure there isn't a trailing space for directories |
| 40 |
if [[ ${#COMPREPLY[@]} == 1 ]]; then |
| 41 |
if [[ -d ${COMPREPLY[0]} ]]; then |
| 42 |
COMPREPLY[0]=$( echo ${COMPREPLY[0]} | sed 's/$/\//' ) |
| 43 |
# If there's only one option, without =, then allow a space |
| 44 |
compopt -o nospace |
| 45 |
fi |
| 46 |
if [[ ${COMPREPLY[0]} == "--"*"=" ]]; then |
| 47 |
compopt -o nospace |
| 48 |
fi |
| 49 |
fi |
| 50 |
;; |
| 51 |
bin2hex) |
| 52 |
;; |
| 53 |
launch) |
| 54 |
if [[ "$COMP_CWORD" == "3" ]]; then |
| 55 |
COMPREPLY=( $( compgen -W '--no-reset' -- $cur ) ) |
| 56 |
fi |
| 57 |
;; |
| 58 |
read) |
| 59 |
# only either user or eeprom should be displayed based on if device has |
| 60 |
# either feature -- or either one is selected when both features exist |
| 61 |
flags="--force --user --eeprom --bin" |
| 62 |
eeprom_size=$( echo $TARGET_INFO | sed "s/.* $target:://" | sed 's/ .*//' ) |
| 63 |
if [[ "$eeprom_size" == 0 ]]; then |
| 64 |
flags=$( echo $flags | sed 's/--eeprom//' ) |
| 65 |
fi |
| 66 |
COMPREPLY=( $( compgen -W "$flags" -- $cur ) ) |
| 67 |
;; |
| 68 |
erase) |
| 69 |
COMPREPLY=( $( compgen -W '--force --suppress-validation' -- $cur ) ) |
| 70 |
;; |
| 71 |
flash) |
| 72 |
filetype="hex" |
| 73 |
flags="--force --user --eeprom --bin --suppress-validation --suppress-bootloader-mem --validate-first --ignore-outside --serial=" |
| 74 |
eeprom_size=$( echo $TARGET_INFO | sed "s/.* $target:://" | sed 's/ .*//' ) |
| 75 |
if [[ "$eeprom_size" == 0 ]]; then |
| 76 |
flags=$( echo $flags | sed 's/--eeprom//' ) |
| 77 |
fi |
| 78 |
for (( i = 3; i < COMP_CWORD; i++ )); do |
| 79 |
if [[ "${COMP_WORDS[i]}" == *.@(bin|hex) ]]; then |
| 80 |
filetype="none" |
| 81 |
flags=$( echo $flags | sed 's/--bin//' ) |
| 82 |
elif [[ "${COMP_WORDS[i]}" == --bin ]]; then |
| 83 |
if [[ filetype != none ]]; then |
| 84 |
filetype="bin" |
| 85 |
fi |
| 86 |
flags=$( echo $flags | sed 's/--bin//' ) |
| 87 |
elif [[ "${COMP_WORDS[i]}" == --@(user|eeprom) ]]; then |
| 88 |
flags=$( echo $flags | sed 's/--user//' ) |
| 89 |
flags=$( echo $flags | sed 's/--eeprom//' ) |
| 90 |
else |
| 91 |
flags=$( echo $flags | sed "s/${COMP_WORDS[i]}//" ) |
| 92 |
fi |
| 93 |
done |
| 94 |
COMPREPLY=( $( compgen -W "$flags" -- $cur ) ) |
| 95 |
if [[ $filetype != none ]]; then |
| 96 |
#COMPREPLY+=( $( compgen -f -X "!*.$filetype" -- $cur ) ) |
| 97 |
COMPREPLY+=( $( compgen -o plusdirs -f -X "!*.$filetype" -- $cur ) ) |
| 98 |
fi |
| 99 |
|
| 100 |
#if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != "--"*"=" ]] ; then |
| 101 |
# make sure there isn't a trailing space for directories |
| 102 |
if [[ ${#COMPREPLY[@]} == 1 ]]; then |
| 103 |
if [[ -d ${COMPREPLY[0]} ]]; then |
| 104 |
COMPREPLY[0]=$( echo ${COMPREPLY[0]} | sed 's/$/\//' ) |
| 105 |
# If there's only one option, without =, then allow a space |
| 106 |
compopt -o nospace |
| 107 |
fi |
| 108 |
if [[ ${COMPREPLY[0]} == "--"*"=" ]]; then |
| 109 |
compopt -o nospace |
| 110 |
fi |
| 111 |
fi |
| 112 |
|
| 113 |
;; |
| 114 |
setsecure) |
| 115 |
;; |
| 116 |
configure) |
| 117 |
;; |
| 118 |
get) |
| 119 |
;; |
| 120 |
getfuse) |
| 121 |
COMPREPLY=( $( compgen -W 'LOCK EPFL BOOTPROT BODLEVEL BODHYST BODEN ISP_BOD_EN ISP_IO_COND_EN ISP_FORCE' -- $cur ) ) |
| 122 |
;; |
| 123 |
setfuse) |
| 124 |
COMPREPLY=( $( compgen -W 'LOCK EPFL BOOTPROT BODLEVEL BODHYST BODEN ISP_BOD_EN ISP_IO_COND_EN ISP_FORCE' -- $cur ) ) |
| 125 |
;; |
| 126 |
esac |
| 127 |
fi |
| 128 |
|
| 129 |
return 0 |
| 130 |
} |
| 131 |
|
| 132 |
complete -F _dfu-programmer dfu-programmer |