Fix some lint warnings in Bash completions

This commit is contained in:
ISSOtm
2022-08-10 00:16:05 +02:00
parent d7d524294b
commit 9ef7954670
4 changed files with 79 additions and 80 deletions

View File

@@ -11,7 +11,7 @@
# - Directories are not completed as such in "coalesced" short-opt arguments. For example, # - Directories are not completed as such in "coalesced" short-opt arguments. For example,
# `rgbasm -M d<tab>` can autocomplete to `rgbasm -M dir/` (no space), but # `rgbasm -M d<tab>` can autocomplete to `rgbasm -M dir/` (no space), but
# `rgbasm -Md<tab>` would autocomplete to `rgbasm -Mdir ` (trailing space) instead. # `rgbasm -Md<tab>` would autocomplete to `rgbasm -Mdir ` (trailing space) instead.
# This is because dircetory handling is performed by Readline, whom we can't tell about the short # This is because directory handling is performed by Readline, whom we can't tell about the short
# opt kerfuffle. The user can work around by separating the argument, as shown above. # opt kerfuffle. The user can work around by separating the argument, as shown above.
# (Also, there might be more possible bugs if `-Mdir` is actually a directory. Ugh.) # (Also, there might be more possible bugs if `-Mdir` is actually a directory. Ugh.)
@@ -20,8 +20,6 @@
# Thus, we don't need to do much to handle that form of argument passing: skip '=' after long opts. # Thus, we don't need to do much to handle that form of argument passing: skip '=' after long opts.
_rgbasm_completions() { _rgbasm_completions() {
COMPREPLY=()
# Format: "long_opt:state_after" # Format: "long_opt:state_after"
# Empty long opt = it doesn't exit # Empty long opt = it doesn't exit
# See the `state` variable below for info about `state_after` # See the `state` variable below for info about `state_after`
@@ -58,6 +56,18 @@ _rgbasm_completions() {
# "normal" is not returned, `optlen` will be set to the length (dash included) of the "option" # "normal" is not returned, `optlen` will be set to the length (dash included) of the "option"
# part of the argument. # part of the argument.
parse_short_opt() { parse_short_opt() {
# These options act like a long option (= takes up the entire word), but only use a single dash
# So, they need some special handling
if [[ "$1" = "-M"[GP] ]]; then
state=normal
optlen=${#1}
return;
elif [[ "$1" = "-M"[QT] ]]; then
state='glob-*.d *.mk *.o'
optlen=${#1}
return;
fi
for (( i = 1; i < "${#1}"; i++ )); do for (( i = 1; i < "${#1}"; i++ )); do
# If the option is not known, assume it doesn't take an argument # If the option is not known, assume it doesn't take an argument
local opt="${opts["${1:$i:1}"]:-":normal"}" local opt="${opts["${1:$i:1}"]:-":normal"}"
@@ -71,7 +81,7 @@ _rgbasm_completions() {
optlen=0 optlen=0
} }
for (( i = 1; i < $COMP_CWORD; i++ )); do for (( i = 1; i < COMP_CWORD; i++ )); do
local word="${COMP_WORDS[$i]}" local word="${COMP_WORDS[$i]}"
# If currently processing an argument, skip this word # If currently processing an argument, skip this word
@@ -87,7 +97,7 @@ _rgbasm_completions() {
fi fi
# Check if it's a long option # Check if it's a long option
if [[ "${word:0:2}" = '--' ]]; then if [[ "$word" = '--'* ]]; then
# If the option is unknown, assume it takes no arguments: keep the state at "normal" # If the option is unknown, assume it takes no arguments: keep the state at "normal"
for long_opt in "${opts[@]}"; do for long_opt in "${opts[@]}"; do
if [[ "$word" = "--${long_opt%%:*}" ]]; then if [[ "$word" = "--${long_opt%%:*}" ]]; then
@@ -103,15 +113,7 @@ _rgbasm_completions() {
fi fi
done done
# Check if it's a short option # Check if it's a short option
elif [[ "${word:0:1}" = '-' ]]; then elif [[ "$word" = '-'* ]]; then
# The `-M?` ones are a mix of short and long, augh
# They must match the *full* word, but only take a single dash
# So, handle them here
if [[ "$1" = "-M"[GP] ]]; then
state=normal
elif [[ "$1" = "-M"[TQ] ]]; then
state='glob-*.d *.mk *.o'
else
parse_short_opt "$word" parse_short_opt "$word"
# The last option takes an argument... # The last option takes an argument...
if [[ "$state" != 'normal' ]]; then if [[ "$state" != 'normal' ]]; then
@@ -124,7 +126,6 @@ _rgbasm_completions() {
fi fi
fi fi
fi fi
fi
done done
# Parse current word # Parse current word
@@ -132,26 +133,26 @@ _rgbasm_completions() {
local cur_word="${COMP_WORDS[$COMP_CWORD]}" local cur_word="${COMP_WORDS[$COMP_CWORD]}"
# Process options, as short ones may change the state # Process options, as short ones may change the state
if $opt_ena && [[ "$state" = 'normal' && "${cur_word:0:1}" = '-' ]]; then if $opt_ena && [[ "$state" = 'normal' && "$cur_word" = '-'* ]]; then
# We might want to complete to an option or an arg to that option # We might want to complete to an option or an arg to that option
# Parse the option word to check # Parse the option word to check
# There's no whitespace in the option names, so we can ride a little dirty... # There's no whitespace in the option names, so we can ride a little dirty...
# Is this a long option? # Is this a long option?
if [[ "${cur_word:1:1}" = '-' ]]; then if [[ "$cur_word" = '--'* ]]; then
# It is, try to complete one # It is, try to complete one
COMPREPLY+=( $(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}") ) mapfile -t COMPREPLY < <(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}")
return 0
elif [[ "$cur_word" = '-M'[GPQT] ]]; then
# These options act like long opts with no arguments, so return them and exactly them
COMPREPLY=( "$cur_word" )
return 0 return 0
else else
# Short options may be grouped, parse them to determine what to complete # Short options may be grouped, parse them to determine what to complete
# The `-M?` ones may not be followed by anything
if [[ "$1" != "-M"[GPTQ] ]]; then
parse_short_opt "$cur_word" parse_short_opt "$cur_word"
# We got some short options that behave like long ones
COMPREPLY+=( $(compgen -W '-MG -MP -MT -MQ' -- "$cur_word") )
if [[ "$state" = 'normal' ]]; then if [[ "$state" = 'normal' ]]; then
COMPREPLY+=( $(compgen -W "${!opts[*]}" -P "$cur_word" '') ) mapfile -t COMPREPLY < <(compgen -W "${!opts[*]}" -P "$cur_word" ''; compgen -W '-MG -MP -MQ -MT' "$cur_word")
return 0 return 0
elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then
# This short option group only awaits its argument! # This short option group only awaits its argument!
@@ -159,18 +160,18 @@ _rgbasm_completions() {
# so that the next completion request switches to the argument # so that the next completion request switches to the argument
# An exception is made for warnings, since it's idiomatic to stick them to the # An exception is made for warnings, since it's idiomatic to stick them to the
# `-W`, and it doesn't break anything. # `-W`, and it doesn't break anything.
COMPREPLY+=( "$cur_word" ) COMPREPLY=( "$cur_word" )
return 0 return 0
fi fi
fi fi
fi fi
fi
COMPREPLY=()
case "$state" in case "$state" in
unk) # Return with no replies: no idea what to complete! unk) # Return with no replies: no idea what to complete!
;; ;;
warning) warning)
COMPREPLY+=( $(compgen -W " mapfile -t COMPREPLY < <(compgen -W "
assert assert
backwards-for backwards-for
builtin-args builtin-args
@@ -192,7 +193,7 @@ _rgbasm_completions() {
all all
extra extra
everything everything
error" -P "${cur_word:0:$optlen}" -- "${cur_word:$optlen}") ) error" -P "${cur_word:0:$optlen}" -- "${cur_word:$optlen}")
;; ;;
normal) # Acts like a glob... normal) # Acts like a glob...
state="glob-*.asm *.inc *.sm83" state="glob-*.asm *.inc *.sm83"

View File

@@ -3,8 +3,6 @@
# Same notes as RGBASM # Same notes as RGBASM
_rgbfix_completions() { _rgbfix_completions() {
COMPREPLY=()
# Format: "long_opt:state_after" # Format: "long_opt:state_after"
# Empty long opt = it doesn't exit # Empty long opt = it doesn't exit
# See the `state` variable below for info about `state_after` # See the `state` variable below for info about `state_after`
@@ -54,7 +52,7 @@ _rgbfix_completions() {
optlen=0 optlen=0
} }
for (( i = 1; i < $COMP_CWORD; i++ )); do for (( i = 1; i < COMP_CWORD; i++ )); do
local word="${COMP_WORDS[$i]}" local word="${COMP_WORDS[$i]}"
# If currently processing an argument, skip this word # If currently processing an argument, skip this word
@@ -70,7 +68,7 @@ _rgbfix_completions() {
fi fi
# Check if it's a long option # Check if it's a long option
if [[ "${word:0:2}" = '--' ]]; then if [[ "$word" = '--'* ]]; then
# If the option is unknown, assume it takes no arguments: keep the state at "normal" # If the option is unknown, assume it takes no arguments: keep the state at "normal"
for long_opt in "${opts[@]}"; do for long_opt in "${opts[@]}"; do
if [[ "$word" = "--${long_opt%%:*}" ]]; then if [[ "$word" = "--${long_opt%%:*}" ]]; then
@@ -86,7 +84,7 @@ _rgbfix_completions() {
fi fi
done done
# Check if it's a short option # Check if it's a short option
elif [[ "${word:0:1}" = '-' ]]; then elif [[ "$word" = '-'* ]]; then
parse_short_opt "$word" parse_short_opt "$word"
# The last option takes an argument... # The last option takes an argument...
if [[ "$state" != 'normal' ]]; then if [[ "$state" != 'normal' ]]; then
@@ -106,22 +104,22 @@ _rgbfix_completions() {
local cur_word="${COMP_WORDS[$COMP_CWORD]}" local cur_word="${COMP_WORDS[$COMP_CWORD]}"
# Process options, as short ones may change the state # Process options, as short ones may change the state
if $opt_ena && [[ "$state" = 'normal' && "${cur_word:0:1}" = '-' ]]; then if $opt_ena && [[ "$state" = 'normal' && "$cur_word" = '-'* ]]; then
# We might want to complete to an option or an arg to that option # We might want to complete to an option or an arg to that option
# Parse the option word to check # Parse the option word to check
# There's no whitespace in the option names, so we can ride a little dirty... # There's no whitespace in the option names, so we can ride a little dirty...
# Is this a long option? # Is this a long option?
if [[ "${cur_word:1:1}" = '-' ]]; then if [[ "$cur_word" = '--'* ]]; then
# It is, try to complete one # It is, try to complete one
COMPREPLY+=( $(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}") ) mapfile -t COMPREPLY < <(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}")
return 0 return 0
else else
# Short options may be grouped, parse them to determine what to complete # Short options may be grouped, parse them to determine what to complete
parse_short_opt "$cur_word" parse_short_opt "$cur_word"
if [[ "$state" = 'normal' ]]; then if [[ "$state" = 'normal' ]]; then
COMPREPLY+=( $(compgen -W "${!opts[*]}" -P "$cur_word" '') ) mapfile -t COMPREPLY < <(compgen -W "${!opts[*]}" -P "$cur_word" '')
return 0 return 0
elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then
# This short option group only awaits its argument! # This short option group only awaits its argument!
@@ -129,22 +127,25 @@ _rgbfix_completions() {
# so that the next completion request switches to the argument # so that the next completion request switches to the argument
# An exception is made for warnings, since it's idiomatic to stick them to the # An exception is made for warnings, since it's idiomatic to stick them to the
# `-W`, and it doesn't break anything. # `-W`, and it doesn't break anything.
COMPREPLY+=( "$cur_word" ) COMPREPLY=( "$cur_word" )
return 0 return 0
fi fi
fi fi
fi fi
COMPREPLY=()
case "$state" in case "$state" in
unk) # Return with no replies: no idea what to complete! unk) # Return with no replies: no idea what to complete!
;; ;;
fix-spec) fix-spec)
COMPREPLY+=( "${cur_word}"{l,h,g,L,H,G} ) COMPREPLY=( "${cur_word}"{l,h,g,L,H,G} )
;; ;;
mbc) mbc)
local cur_arg="${cur_word:$optlen}" local cur_arg="${cur_word:$optlen}"
cur_arg="${cur_arg@U}" cur_arg="${cur_arg@U}"
COMPREPLY=( $(compgen -W " compopt -o nosort # Keep `help` first in the list, mainly
mapfile -t COMPREPLY < <(compgen -W "help" -P "${cur_word:0:$optlen}" -- "${cur_word:$optlen}")
mapfile -t COMPREPLY -O ${#COMPREPLY} < <(compgen -W "
ROM_ONLY ROM_ONLY
MBC1{,+RAM,+RAM+BATTERY} MBC1{,+RAM,+RAM+BATTERY}
MBC2{,+BATTERY} MBC2{,+BATTERY}
@@ -157,8 +158,7 @@ _rgbfix_completions() {
BANDAI_TAMA5 BANDAI_TAMA5
HUC3 HUC3
HUC1+RAM+BATTERY HUC1+RAM+BATTERY
TPP1_1.0{,+BATTERY}{,+RTC}{,+RUMBLE,+MULTIRUMBLE}" -P "${cur_word:0:$optlen}" -- "`tr 'a-z ' 'A-Z_' <<<"${cur_word/ /_}"`") ) TPP1_1.0{,+BATTERY}{,+RTC}{,+RUMBLE,+MULTIRUMBLE}" -P "${cur_word:0:$optlen}" -- "${cur_word/ /_}")
COMPREPLY+=( $(compgen -W "help" -P "${cur_word:0:$optlen}" -- "${cur_word:$optlen}") )
;; ;;
normal) # Acts like a glob... normal) # Acts like a glob...
state="glob-*.gb *.gbc *.sgb" state="glob-*.gb *.gbc *.sgb"

View File

@@ -3,8 +3,6 @@
# Same notes as RGBASM # Same notes as RGBASM
_rgbgfx_completions() { _rgbgfx_completions() {
COMPREPLY=()
# Format: "long_opt:state_after" # Format: "long_opt:state_after"
# Empty long opt = it doesn't exit # Empty long opt = it doesn't exit
# See the `state` variable below for info about `state_after` # See the `state` variable below for info about `state_after`
@@ -62,7 +60,7 @@ _rgbgfx_completions() {
optlen=0 optlen=0
} }
for (( i = 1; i < $COMP_CWORD; i++ )); do for (( i = 1; i < COMP_CWORD; i++ )); do
local word="${COMP_WORDS[$i]}" local word="${COMP_WORDS[$i]}"
# If currently processing an argument, skip this word # If currently processing an argument, skip this word
@@ -78,7 +76,7 @@ _rgbgfx_completions() {
fi fi
# Check if it's a long option # Check if it's a long option
if [[ "${word:0:2}" = '--' ]]; then if [[ "$word" = '--'* ]]; then
# If the option is unknown, assume it takes no arguments: keep the state at "normal" # If the option is unknown, assume it takes no arguments: keep the state at "normal"
for long_opt in "${opts[@]}"; do for long_opt in "${opts[@]}"; do
if [[ "$word" = "--${long_opt%%:*}" ]]; then if [[ "$word" = "--${long_opt%%:*}" ]]; then
@@ -94,7 +92,7 @@ _rgbgfx_completions() {
fi fi
done done
# Check if it's a short option # Check if it's a short option
elif [[ "${word:0:1}" = '-' ]]; then elif [[ "$word" = '-'* ]]; then
parse_short_opt "$word" parse_short_opt "$word"
# The last option takes an argument... # The last option takes an argument...
if [[ "$state" != 'normal' ]]; then if [[ "$state" != 'normal' ]]; then
@@ -114,22 +112,22 @@ _rgbgfx_completions() {
local cur_word="${COMP_WORDS[$COMP_CWORD]}" local cur_word="${COMP_WORDS[$COMP_CWORD]}"
# Process options, as short ones may change the state # Process options, as short ones may change the state
if $opt_ena && [[ "$state" = 'normal' && "${cur_word:0:1}" = '-' ]]; then if $opt_ena && [[ "$state" = 'normal' && "$cur_word" = '-'* ]]; then
# We might want to complete to an option or an arg to that option # We might want to complete to an option or an arg to that option
# Parse the option word to check # Parse the option word to check
# There's no whitespace in the option names, so we can ride a little dirty... # There's no whitespace in the option names, so we can ride a little dirty...
# Is this a long option? # Is this a long option?
if [[ "${cur_word:1:1}" = '-' ]]; then if [[ "$cur_word" = '--'* ]]; then
# It is, try to complete one # It is, try to complete one
COMPREPLY+=( $(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}") ) mapfile -t COMPREPLY < <(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}")
return 0 return 0
else else
# Short options may be grouped, parse them to determine what to complete # Short options may be grouped, parse them to determine what to complete
parse_short_opt "$cur_word" parse_short_opt "$cur_word"
if [[ "$state" = 'normal' ]]; then if [[ "$state" = 'normal' ]]; then
COMPREPLY+=( $(compgen -W "${!opts[*]}" -P "$cur_word" '') ) mapfile -t COMPREPLY < <(compgen -W "${!opts[*]}" -P "$cur_word" '')
return 0 return 0
elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then
# This short option group only awaits its argument! # This short option group only awaits its argument!
@@ -137,12 +135,13 @@ _rgbgfx_completions() {
# so that the next completion request switches to the argument # so that the next completion request switches to the argument
# An exception is made for warnings, since it's idiomatic to stick them to the # An exception is made for warnings, since it's idiomatic to stick them to the
# `-W`, and it doesn't break anything. # `-W`, and it doesn't break anything.
COMPREPLY+=( "$cur_word" ) COMPREPLY=( "$cur_word" )
return 0 return 0
fi fi
fi fi
fi fi
COMPREPLY=()
case "$state" in case "$state" in
unk) # Return with no replies: no idea what to complete! unk) # Return with no replies: no idea what to complete!
;; ;;

View File

@@ -3,8 +3,6 @@
# Same notes as RGBASM # Same notes as RGBASM
_rgblink_completions() { _rgblink_completions() {
COMPREPLY=()
# Format: "long_opt:state_after" # Format: "long_opt:state_after"
# Empty long opt = it doesn't exit # Empty long opt = it doesn't exit
# See the `state` variable below for info about `state_after` # See the `state` variable below for info about `state_after`
@@ -52,7 +50,7 @@ _rgblink_completions() {
optlen=0 optlen=0
} }
for (( i = 1; i < $COMP_CWORD; i++ )); do for (( i = 1; i < COMP_CWORD; i++ )); do
local word="${COMP_WORDS[$i]}" local word="${COMP_WORDS[$i]}"
# If currently processing an argument, skip this word # If currently processing an argument, skip this word
@@ -68,7 +66,7 @@ _rgblink_completions() {
fi fi
# Check if it's a long option # Check if it's a long option
if [[ "${word:0:2}" = '--' ]]; then if [[ "$word" = '--'* ]]; then
# If the option is unknown, assume it takes no arguments: keep the state at "normal" # If the option is unknown, assume it takes no arguments: keep the state at "normal"
for long_opt in "${opts[@]}"; do for long_opt in "${opts[@]}"; do
if [[ "$word" = "--${long_opt%%:*}" ]]; then if [[ "$word" = "--${long_opt%%:*}" ]]; then
@@ -84,7 +82,7 @@ _rgblink_completions() {
fi fi
done done
# Check if it's a short option # Check if it's a short option
elif [[ "${word:0:1}" = '-' ]]; then elif [[ "$word" = '-'* ]]; then
parse_short_opt "$word" parse_short_opt "$word"
# The last option takes an argument... # The last option takes an argument...
if [[ "$state" != 'normal' ]]; then if [[ "$state" != 'normal' ]]; then
@@ -104,22 +102,22 @@ _rgblink_completions() {
local cur_word="${COMP_WORDS[$COMP_CWORD]}" local cur_word="${COMP_WORDS[$COMP_CWORD]}"
# Process options, as short ones may change the state # Process options, as short ones may change the state
if $opt_ena && [[ "$state" = 'normal' && "${cur_word:0:1}" = '-' ]]; then if $opt_ena && [[ "$state" = 'normal' && "$cur_word" = '-'* ]]; then
# We might want to complete to an option or an arg to that option # We might want to complete to an option or an arg to that option
# Parse the option word to check # Parse the option word to check
# There's no whitespace in the option names, so we can ride a little dirty... # There's no whitespace in the option names, so we can ride a little dirty...
# Is this a long option? # Is this a long option?
if [[ "${cur_word:1:1}" = '-' ]]; then if [[ "$cur_word" = '--'* ]]; then
# It is, try to complete one # It is, try to complete one
COMPREPLY+=( $(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}") ) mapfile -t COMPREPLY < <(compgen -W "${opts[*]%%:*}" -P '--' -- "${cur_word#--}")
return 0 return 0
else else
# Short options may be grouped, parse them to determine what to complete # Short options may be grouped, parse them to determine what to complete
parse_short_opt "$cur_word" parse_short_opt "$cur_word"
if [[ "$state" = 'normal' ]]; then if [[ "$state" = 'normal' ]]; then
COMPREPLY+=( $(compgen -W "${!opts[*]}" -P "$cur_word" '') ) mapfile -t COMPREPLY < <(compgen -W "${!opts[*]}" -P "$cur_word" '')
return 0 return 0
elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then elif [[ "$optlen" = "${#cur_word}" && "$state" != "warning" ]]; then
# This short option group only awaits its argument! # This short option group only awaits its argument!
@@ -127,12 +125,13 @@ _rgblink_completions() {
# so that the next completion request switches to the argument # so that the next completion request switches to the argument
# An exception is made for warnings, since it's idiomatic to stick them to the # An exception is made for warnings, since it's idiomatic to stick them to the
# `-W`, and it doesn't break anything. # `-W`, and it doesn't break anything.
COMPREPLY+=( "$cur_word" ) COMPREPLY=( "$cur_word" )
return 0 return 0
fi fi
fi fi
fi fi
COMPREPLY=()
case "$state" in case "$state" in
unk) # Return with no replies: no idea what to complete! unk) # Return with no replies: no idea what to complete!
;; ;;