aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Barnes <craigbarnes@protonmail.com>2023-01-10 19:44:24 +0000
committerCraig Barnes <craigbarnes@protonmail.com>2023-01-10 19:44:24 +0000
commit8acc10b9d4bc1d4c245475e1812093bf8c9e3d78 (patch)
tree70c6ec28477a1afc6d15ee2d40071e87f9cfdbbb
parentUse "command -v" instead of "which" in bash completion scripts (diff)
completions: bash: use "case" instead of long if/elif/else chain
-rw-r--r--completions/bash/foot50
-rw-r--r--completions/bash/footclient45
2 files changed, 52 insertions, 43 deletions
diff --git a/completions/bash/foot b/completions/bash/foot
index b427bc58..c1bb20fa 100644
--- a/completions/bash/foot
+++ b/completions/bash/foot
@@ -31,7 +31,7 @@ _foot()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
- # check if positional argument is completed
+ # Check if positional argument is completed
previous_words=( "${COMP_WORDS[@]}" )
unset previous_words[-1]
commands=$(compgen -c | grep -vFx "$(compgen -k)" | grep -vE '^([.:[]|foot)$' | sort -u)
@@ -43,40 +43,44 @@ _foot()
(( i++ ))
continue
fi
- # positional argument found
+ # Positional argument found
offset=$i
fi
(( i++ ))
done
if [[ ! -z "$offset" ]] ; then
- # depends on bash_completion being available
+ # Depends on bash_completion being available
declare -F _command_offset >/dev/null || return 1
_command_offset $offset
+ return 0
elif [[ ${cur} == --* ]] ; then
COMPREPLY=( $(compgen -W "${flags}" -- ${cur}) )
- elif [[ ${prev} =~ ^(--config|--print-pid|--server)$ ]] ; then
- compopt -o default
- elif [[ ${prev} == '--working-directory' ]] ; then
- compopt -o dirnames
- elif [[ ${prev} == '--term' ]] ; then
- # check if toe is available
+ return 0
+ fi
+
+ case "$prev" in
+ --config|--print-pid|--server)
+ compopt -o default ;;
+ --working-directory)
+ compopt -o dirnames ;;
+ --term)
command -v toe > /dev/null || return 1
- COMPREPLY=( $(compgen -W "$(toe -a | awk '$1 ~ /[+]/ {next}; {print $1}')" -- ${cur}) )
- elif [[ ${prev} == '--font' ]] ; then
- # check if fc-list is available
+ COMPREPLY=( $(compgen -W "$(toe -a | awk '$1 ~ /[+]/ {next}; {print $1}')" -- ${cur}) ) ;;
+ --font)
command -v fc-list > /dev/null || return 1
- COMPREPLY=( $(compgen -W "$(fc-list : family | sed 's/,/\n/g' | uniq | tr -d ' ')" -- ${cur}) )
- elif [[ ${prev} == '--log-level' ]] ; then
- COMPREPLY=( $(compgen -W "none error warning info" -- ${cur}) )
- elif [[ ${prev} == '--log-colorize' ]] ; then
- COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) )
- elif [[ ${prev} =~ ^(--app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels|--check-config)$ ]] ; then
- : # don't autocomplete for these flags
- else
- # complete commands from $PATH
- COMPREPLY=( $(compgen -c -- ${cur}) )
- fi
+ COMPREPLY=( $(compgen -W "$(fc-list : family | sed 's/,/\n/g' | uniq | tr -d ' ')" -- ${cur}) ) ;;
+ --log-level)
+ COMPREPLY=( $(compgen -W "none error warning info" -- ${cur}) ) ;;
+ --log-colorize)
+ COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) ) ;;
+ --app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels|--check-config)
+ # Don't autocomplete for these flags
+ : ;;
+ *)
+ # Complete commands from $PATH
+ COMPREPLY=( $(compgen -c -- ${cur}) ) ;;
+ esac
return 0
}
diff --git a/completions/bash/footclient b/completions/bash/footclient
index 0381e8a0..39cb070e 100644
--- a/completions/bash/footclient
+++ b/completions/bash/footclient
@@ -27,7 +27,7 @@ _footclient()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
- # check if positional argument is completed
+ # Check if positional argument is completed
previous_words=( "${COMP_WORDS[@]}" )
unset previous_words[-1]
commands=$(compgen -c | grep -vFx "$(compgen -k)" | grep -vE '^([.:[]|footclient)$' | sort -u)
@@ -39,37 +39,42 @@ _footclient()
(( i++ ))
continue
fi
- # positional argument found
+ # Positional argument found
offset=$i
fi
(( i++ ))
done
if [[ ! -z "$offset" ]] ; then
- # depends on bash_completion being available
+ # Depends on bash_completion being available
declare -F _command_offset >/dev/null || return 1
_command_offset $offset
+ return 0
elif [[ ${cur} == --* ]] ; then
COMPREPLY=( $(compgen -W "${flags}" -- ${cur}) )
- elif [[ ${prev} == '--server-socket' ]] ; then
- compopt -o default
- elif [[ ${prev} == '--working-directory' ]] ; then
- compopt -o dirnames
- elif [[ ${prev} == '--term' ]] ; then
- # check if toe is available
- command -v toe > /dev/null || return 1
- COMPREPLY=( $(compgen -W "$(toe -a | awk '$1 ~ /[+]/ {next}; {print $1}')" -- ${cur}) )
- elif [[ ${prev} == '--log-level' ]] ; then
- COMPREPLY=( $(compgen -W "none error warning info" -- ${cur}) )
- elif [[ ${prev} == '--log-colorize' ]] ; then
- COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) )
- elif [[ ${prev} =~ ^(--app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels|)$ ]] ; then
- : # don't autocomplete for these flags
- else
- # complete commands from $PATH
- COMPREPLY=( $(compgen -c -- ${cur}) )
+ return 0
fi
+ case "$prev" in
+ --server-socket)
+ compopt -o default ;;
+ --working-directory)
+ compopt -o dirnames ;;
+ --term)
+ command -v toe > /dev/null || return 1
+ COMPREPLY=( $(compgen -W "$(toe -a | awk '$1 ~ /[+]/ {next}; {print $1}')" -- ${cur}) ) ;;
+ --log-level)
+ COMPREPLY=( $(compgen -W "none error warning info" -- ${cur}) ) ;;
+ --log-colorize)
+ COMPREPLY=( $(compgen -W "never always auto" -- ${cur}) ) ;;
+ --app-id|--help|--override|--title|--version|--window-size-chars|--window-size-pixels)
+ # Don't autocomplete for these flags
+ : ;;
+ *)
+ # Complete commands from $PATH
+ COMPREPLY=( $(compgen -c -- ${cur}) ) ;;
+ esac
+
return 0
}