Files
flatpak/completion/flatpak
Mia McMahill 02fc85a3c2 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
2026-06-18 11:15:54 +00:00

48 lines
1.4 KiB
Plaintext

# Check for bash
[ -z "$BASH_VERSION" ] && return
####################################################################################################
__flatpak() {
local IFS=$'\n'
local cur
local -a RES
cur=$(_get_cword :)
readarray -t RES < <(flatpak complete "${COMP_LINE}" "${COMP_POINT}" "${cur}")
COMPREPLY=()
local res
local -a COMPGEN_OPTS
local -a REPLIES
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
COMPGEN_OPTS=()
fi
if [[ ${#COMPGEN_OPTS[@]} -ne 0 ]]; then
local CUR
if [[ $cur == "=" ]]; then
CUR=""
else
CUR="$cur"
fi
readarray -t REPLIES < <(compgen "${COMPGEN_OPTS[@]}" -- "${CUR}")
COMPREPLY+=("${REPLIES[@]}")
else
COMPREPLY=("${COMPREPLY[@]}" "$res")
fi
done
}
####################################################################################################
complete -o nospace -F __flatpak flatpak