mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
Merge branch 'shellcheck-completions' into 'main'
tests: Enable shellcheck for bash completion scripts See merge request GNOME/glib!4012
This commit is contained in:
commit
869ef92858
@ -1,4 +1,6 @@
|
||||
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Check for bash
|
||||
[ -z "$BASH_VERSION" ] && return
|
||||
|
||||
@ -7,6 +9,7 @@
|
||||
__app() {
|
||||
case "${COMP_CWORD}" in
|
||||
1)
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "help version list-apps launch action list-actions" -- "${COMP_WORDS[1]}"))
|
||||
return 0
|
||||
;;
|
||||
@ -14,7 +17,8 @@ __app() {
|
||||
2)
|
||||
case "${COMP_WORDS[1]}" in
|
||||
launch|action|list-actions)
|
||||
COMPREPLY=($(compgen -W "`gapplication list-apps`" -- "${COMP_WORDS[2]}"))
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "$(gapplication list-apps)" -- "${COMP_WORDS[2]}"))
|
||||
return 0
|
||||
;;
|
||||
|
||||
@ -31,7 +35,8 @@ __app() {
|
||||
action)
|
||||
# Word 3 is the action name. This is the only one we can help with.
|
||||
if [ "${COMP_CWORD}" == 3 ]; then
|
||||
COMPREPLY=($(compgen -W "`gapplication list-actions "${COMP_WORDS[2]}"`" -- "${COMP_WORDS[3]}"))
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "$(gapplication list-actions "${COMP_WORDS[2]}")" -- "${COMP_WORDS[3]}"))
|
||||
return 0
|
||||
else
|
||||
COMPREPLY=()
|
||||
@ -40,6 +45,7 @@ __app() {
|
||||
;;
|
||||
launch)
|
||||
# Filenames...
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -A file "${COMP_WORDS[COMP_CWORD]}"))
|
||||
return 0
|
||||
;;
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Check for bash
|
||||
[ -z "$BASH_VERSION" ] && return
|
||||
|
||||
@ -7,9 +9,12 @@
|
||||
|
||||
__gdbus() {
|
||||
local IFS=$'\n'
|
||||
local cur=`_get_cword :`
|
||||
local cur
|
||||
cur="$(_get_cword :)"
|
||||
|
||||
local suggestions=$(gdbus complete "${COMP_LINE}" ${COMP_POINT})
|
||||
local suggestions
|
||||
suggestions="$(gdbus complete "${COMP_LINE}" "${COMP_POINT}")"
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "$suggestions" -- "$cur"))
|
||||
|
||||
# Remove colon-word prefix from COMPREPLY items
|
||||
@ -17,10 +22,10 @@ __gdbus() {
|
||||
*:*)
|
||||
case "$COMP_WORDBREAKS" in
|
||||
*:*)
|
||||
local colon_word=${cur%${cur##*:}}
|
||||
local colon_word=${cur%"${cur##*:}"}
|
||||
local i=${#COMPREPLY[*]}
|
||||
while [ $((--i)) -ge 0 ]; do
|
||||
COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
|
||||
COMPREPLY[i]=${COMPREPLY[i]#"$colon_word"}
|
||||
done
|
||||
;;
|
||||
esac
|
||||
|
@ -15,6 +15,8 @@
|
||||
# along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Check for bash
|
||||
[ -z "$BASH_VERSION" ] && return
|
||||
|
||||
@ -45,13 +47,13 @@ __gio_location() {
|
||||
dir="$cur"
|
||||
elif [[ $cur =~ "/" ]]; then
|
||||
# Subtract basename because dirname cmd doesn't work well with schemes
|
||||
dir=${cur%$(basename "$cur")}
|
||||
dir=${cur%"$(basename "$cur")"}
|
||||
fi
|
||||
|
||||
# List volumes and mounts
|
||||
local mounts=( )
|
||||
local mount
|
||||
while IFS=$'\n' read mount; do
|
||||
while IFS=$'\n' read -r mount; do
|
||||
# Do not care about local mounts
|
||||
[[ "$mount" =~ ^"file:" ]] && continue
|
||||
|
||||
@ -66,10 +68,11 @@ __gio_location() {
|
||||
# List files
|
||||
local files=()
|
||||
local names=()
|
||||
local name size type
|
||||
while IFS=$'\t' read name size type; do
|
||||
local name type
|
||||
while IFS=$'\t' read -r name _ type; do
|
||||
# Escape name properly
|
||||
local escaped_name="$(printf "%q" "$name")"
|
||||
local escaped_name
|
||||
escaped_name="$(printf "%q" "$name")"
|
||||
|
||||
# Append slash for directories and space for files
|
||||
if [[ "$type" == "(directory)" ]]; then
|
||||
@ -107,7 +110,8 @@ __gio_location() {
|
||||
|
||||
__gio() {
|
||||
# Complete subcommands
|
||||
if (( ${COMP_CWORD} == 1 )); then
|
||||
if (( COMP_CWORD == 1 )); then
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "help version cat copy info launch list mime mkdir monitor mount move open rename remove save set trash tree" -- "${COMP_WORDS[1]}"))
|
||||
compopt +o nospace
|
||||
return 0
|
||||
|
@ -1,15 +1,16 @@
|
||||
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Check for bash
|
||||
[ -z "$BASH_VERSION" ] && return
|
||||
|
||||
####################################################################################################
|
||||
|
||||
__gresource() {
|
||||
local choices coffset section
|
||||
local choices coffset
|
||||
|
||||
if [ ${COMP_CWORD} -gt 2 ]; then
|
||||
if [ ${COMP_WORDS[1]} = --section ]; then
|
||||
section=${COMP_WORDS[2]}
|
||||
if [ "${COMP_CWORD}" -gt 2 ]; then
|
||||
if [ "${COMP_WORDS[1]}" = --section ]; then
|
||||
coffset=2
|
||||
else
|
||||
coffset=0
|
||||
@ -18,13 +19,13 @@ __gresource() {
|
||||
coffset=0
|
||||
fi
|
||||
|
||||
case "$((${COMP_CWORD}-$coffset))" in
|
||||
case "$((COMP_CWORD-coffset))" in
|
||||
1)
|
||||
choices=$'--section \nhelp \nsections \nlist \ndetails \nextract '
|
||||
;;
|
||||
|
||||
2)
|
||||
case "${COMP_WORDS[$(($coffset+1))]}" in
|
||||
case "${COMP_WORDS[$((coffset+1))]}" in
|
||||
--section)
|
||||
return 0
|
||||
;;
|
||||
@ -34,22 +35,24 @@ __gresource() {
|
||||
;;
|
||||
|
||||
sections|list|details|extract)
|
||||
COMPREPLY=($(compgen -f -- ${COMP_WORDS[${COMP_CWORD}]}))
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -f -- "${COMP_WORDS[${COMP_CWORD}]}"))
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
3)
|
||||
case "${COMP_WORDS[$(($coffset+1))]}" in
|
||||
case "${COMP_WORDS[$((coffset+1))]}" in
|
||||
list|details|extract)
|
||||
choices="$(gresource list ${COMP_WORDS[$(($coffset+2))]} 2> /dev/null | sed -e 's.$. .')"
|
||||
choices="$(gresource list "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null | sed -e 's.$. .')"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
local IFS=$'\n'
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${choices}" -- "${COMP_WORDS[${COMP_CWORD}]}"))
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
# shellcheck shell=bash
|
||||
|
||||
# Check for bash
|
||||
[ -z "$BASH_VERSION" ] && return
|
||||
|
||||
@ -7,8 +9,8 @@
|
||||
__gsettings() {
|
||||
local choices coffset schemadir=""
|
||||
|
||||
if [ ${COMP_CWORD} -gt 2 ]; then
|
||||
if [ ${COMP_WORDS[1]} = --schemadir ]; then
|
||||
if [ "${COMP_CWORD}" -gt 2 ]; then
|
||||
if [ "${COMP_WORDS[1]}" = --schemadir ]; then
|
||||
# this complexity is needed to perform correct tilde expansion
|
||||
schemadir=$(eval "echo --schemadir ${COMP_WORDS[2]}")
|
||||
coffset=2
|
||||
@ -19,15 +21,16 @@ __gsettings() {
|
||||
coffset=0
|
||||
fi
|
||||
|
||||
case "$((${COMP_CWORD}-$coffset))" in
|
||||
case "$((COMP_CWORD-coffset))" in
|
||||
1)
|
||||
choices=$'--schemadir\n--version\nhelp \nlist-schemas\nlist-relocatable-schemas\nlist-keys \nlist-children \nlist-recursively \nget \nrange \nset \nreset \nreset-recursively \nwritable \nmonitor \ndescribe '
|
||||
;;
|
||||
|
||||
2)
|
||||
case "${COMP_WORDS[$(($coffset+1))]}" in
|
||||
case "${COMP_WORDS[$((coffset+1))]}" in
|
||||
--schemadir)
|
||||
COMPREPLY=($(compgen -o dirnames -- ${COMP_WORDS[${COMP_CWORD}]}))
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -o dirnames -- "${COMP_WORDS[${COMP_CWORD}]}"))
|
||||
return 0
|
||||
;;
|
||||
|
||||
@ -35,38 +38,40 @@ __gsettings() {
|
||||
choices=$'list-schemas\nlist-relocatable-schemas\nlist-keys\nlist-children\nlist-recursively\nget\nrange\nset\nreset\nreset-recursively\nwritable\nmonitor'
|
||||
;;
|
||||
list-keys|list-children|list-recursively|reset-recursively)
|
||||
choices="$(gsettings $schemadir list-schemas 2> /dev/null)"$'\n'"$(gsettings $schemadir list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
|
||||
choices="$(gsettings "$schemadir" list-schemas 2> /dev/null)"$'\n'"$(gsettings "$schemadir" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
|
||||
;;
|
||||
list-schemas)
|
||||
COMPREPLY=($(compgen -W "--print-paths" -- ${COMP_WORDS[${COMP_CWORD}]}))
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "--print-paths" -- "${COMP_WORDS[${COMP_CWORD}]}"))
|
||||
return 0
|
||||
;;
|
||||
|
||||
get|range|set|reset|writable|monitor|describe)
|
||||
choices="$(gsettings $schemadir list-schemas 2> /dev/null | sed -e 's.$. .')"$'\n'"$(gsettings $schemadir list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
|
||||
choices="$(gsettings "$schemadir" list-schemas 2> /dev/null | sed -e 's.$. .')"$'\n'"$(gsettings "$schemadir" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
3)
|
||||
case "${COMP_WORDS[$(($coffset+1))]}" in
|
||||
case "${COMP_WORDS[$((coffset+1))]}" in
|
||||
set)
|
||||
choices="$(gsettings $schemadir list-keys ${COMP_WORDS[$(($coffset+2))]} 2> /dev/null | sed -e 's.$. .')"
|
||||
choices="$(gsettings "$schemadir" list-keys "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null | sed -e 's.$. .')"
|
||||
;;
|
||||
|
||||
get|range|reset|writable|monitor|describe)
|
||||
choices="$(gsettings $schemadir list-keys ${COMP_WORDS[$(($coffset+2))]} 2> /dev/null)"
|
||||
choices="$(gsettings "$schemadir" list-keys "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null)"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
|
||||
4)
|
||||
case "${COMP_WORDS[$(($coffset+2))]}" in
|
||||
case "${COMP_WORDS[$((coffset+2))]}" in
|
||||
set)
|
||||
range=($(gsettings $schemadir range ${COMP_WORDS[$(($coffset+2))]} ${COMP_WORDS[$(($coffset+3))]} 2> /dev/null))
|
||||
# shellcheck disable=SC2207
|
||||
range=($(gsettings "$schemadir" range "${COMP_WORDS[$((coffset+2))]}" "${COMP_WORDS[$((coffset+3))]}" 2> /dev/null))
|
||||
case "${range[0]}" in
|
||||
enum)
|
||||
unset range[0]
|
||||
unset 'range[0]'
|
||||
;;
|
||||
*)
|
||||
unset range
|
||||
@ -80,6 +85,7 @@ __gsettings() {
|
||||
esac
|
||||
|
||||
local IFS=$'\n'
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${choices}" -- "${COMP_WORDS[${COMP_CWORD}]}"))
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ export TEST_REQUIRES_TOOLS="git shellcheck"
|
||||
run_lint () {
|
||||
# Ignoring third-party directories that we don't want to parse
|
||||
# shellcheck disable=SC2046
|
||||
shellcheck $(git ls-files '*.sh' | grep -Ev "glib/libcharset|glib/dirent")
|
||||
shellcheck $(git ls-files '*.sh' 'gio/completion/' | grep -Ev "glib/libcharset|glib/dirent|gitignore")
|
||||
}
|
||||
|
||||
# shellcheck source=tests/lint-common.sh
|
||||
|
Loading…
Reference in New Issue
Block a user