completion: Minor cleanup of variable usage in bash completion

1. Removed unnecessary punctuation to help with readability
2. Loop over RES elements directly instead of indexing
3. Declare COMPGEN_OPTS only once vs redeclaring on each iteration
This commit is contained in:
Mia McMahill
2026-06-07 23:26:07 -05:00
committed by Sebastian Wick
parent 21ae7723c0
commit 02fc85a3c2

View File

@@ -11,32 +11,33 @@ __flatpak() {
readarray -t RES < <(flatpak complete "${COMP_LINE}" "${COMP_POINT}" "${cur}")
COMPREPLY=()
local i
local res
local -a COMPGEN_OPTS
local -a REPLIES
for i in "${!RES[@]}"; do
if [[ "${RES[$i]}" = "__FLATPAK_FILE" ]]; then
declare -a COMPGEN_OPTS=('-f')
elif [[ "${RES[$i]}" = "__FLATPAK_BUNDLE_FILE" ]]; then
declare -a COMPGEN_OPTS=('-f' '-X' '!*.flatpak')
elif [[ "${RES[$i]}" = "__FLATPAK_BUNDLE_OR_REF_FILE" ]]; then
declare -a COMPGEN_OPTS=('-f' '-X' '!*.flatpak@(|ref)')
elif [[ "${RES[$i]}" = "__FLATPAK_DIR" ]]; then
declare -a COMPGEN_OPTS=('-d')
for res in "${RES[@]}"; do
if [[ $res == "__FLATPAK_FILE" ]]; then
COMPGEN_OPTS=('-f')
elif [[ $res == "__FLATPAK_BUNDLE_FILE" ]]; then
COMPGEN_OPTS=('-f' '-X' '!*.flatpak')
elif [[ $res == "__FLATPAK_BUNDLE_OR_REF_FILE" ]]; then
COMPGEN_OPTS=('-f' '-X' '!*.flatpak@(|ref)')
elif [[ $res == "__FLATPAK_DIR" ]]; then
COMPGEN_OPTS=('-d')
else
declare -a COMPGEN_OPTS=()
COMPGEN_OPTS=()
fi
if [[ ${#COMPGEN_OPTS[@]} -ne 0 ]]; then
local CUR
if [[ "${cur}" = "=" ]]; then
if [[ $cur == "=" ]]; then
CUR=""
else
CUR="${cur}"
CUR="$cur"
fi
readarray -t REPLIES < <(compgen "${COMPGEN_OPTS[@]}" -- "${CUR}")
COMPREPLY+=("${REPLIES[@]}")
else
COMPREPLY=("${COMPREPLY[@]}" "${RES[$i]}")
COMPREPLY=("${COMPREPLY[@]}" "$res")
fi
done
}