From f95e8b4e7cb33692dcc42977ca8faa16bc054fc4 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 13:51:44 +0100 Subject: [PATCH 01/11] completion: Add shellcheck shell hints to all completion scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because completion scripts are not executed directly, they don’t have a shebang line, so shellcheck can’t be sure which shell syntax to use for them. Help it out. Signed-off-by: Philip Withnall --- gio/completion/gapplication | 2 ++ gio/completion/gdbus | 2 ++ gio/completion/gio | 2 ++ gio/completion/gresource | 2 ++ gio/completion/gsettings | 2 ++ 5 files changed, 10 insertions(+) diff --git a/gio/completion/gapplication b/gio/completion/gapplication index 565025bd8..ed592bb24 100644 --- a/gio/completion/gapplication +++ b/gio/completion/gapplication @@ -1,4 +1,6 @@ +# shellcheck shell=bash + # Check for bash [ -z "$BASH_VERSION" ] && return diff --git a/gio/completion/gdbus b/gio/completion/gdbus index 79f4cb4b4..c9418fb06 100644 --- a/gio/completion/gdbus +++ b/gio/completion/gdbus @@ -1,4 +1,6 @@ +# shellcheck shell=bash + # Check for bash [ -z "$BASH_VERSION" ] && return diff --git a/gio/completion/gio b/gio/completion/gio index c650475b9..2a27a8c39 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -15,6 +15,8 @@ # along with this library; if not, see . # +# shellcheck shell=bash + # Check for bash [ -z "$BASH_VERSION" ] && return diff --git a/gio/completion/gresource b/gio/completion/gresource index ef1145d62..a30c2ade7 100644 --- a/gio/completion/gresource +++ b/gio/completion/gresource @@ -1,4 +1,6 @@ +# shellcheck shell=bash + # Check for bash [ -z "$BASH_VERSION" ] && return diff --git a/gio/completion/gsettings b/gio/completion/gsettings index ef1757636..98ee2b2c4 100644 --- a/gio/completion/gsettings +++ b/gio/completion/gsettings @@ -1,4 +1,6 @@ +# shellcheck shell=bash + # Check for bash [ -z "$BASH_VERSION" ] && return From aaf715a046e79a24e3821d7f5a5a22151bd17ee9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 13:54:33 +0100 Subject: [PATCH 02/11] completion: Stop using old backtick quoting for subcommands Fixes a shellcheck warning. Signed-off-by: Philip Withnall --- gio/completion/gapplication | 4 ++-- gio/completion/gdbus | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gio/completion/gapplication b/gio/completion/gapplication index ed592bb24..429b6cf83 100644 --- a/gio/completion/gapplication +++ b/gio/completion/gapplication @@ -16,7 +16,7 @@ __app() { 2) case "${COMP_WORDS[1]}" in launch|action|list-actions) - COMPREPLY=($(compgen -W "`gapplication list-apps`" -- "${COMP_WORDS[2]}")) + COMPREPLY=($(compgen -W "$(gapplication list-apps)" -- "${COMP_WORDS[2]}")) return 0 ;; @@ -33,7 +33,7 @@ __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]}")) + COMPREPLY=($(compgen -W "$(gapplication list-actions "${COMP_WORDS[2]}")" -- "${COMP_WORDS[3]}")) return 0 else COMPREPLY=() diff --git a/gio/completion/gdbus b/gio/completion/gdbus index c9418fb06..cfe87517b 100644 --- a/gio/completion/gdbus +++ b/gio/completion/gdbus @@ -9,7 +9,7 @@ __gdbus() { local IFS=$'\n' - local cur=`_get_cword :` + local cur="$(_get_cword :)" local suggestions=$(gdbus complete "${COMP_LINE}" ${COMP_POINT}) COMPREPLY=($(compgen -W "$suggestions" -- "$cur")) From c79575362eeb8f8d24cd2c141928d7d8f22eeb94 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 13:58:49 +0100 Subject: [PATCH 03/11] completion: Add missing quoting As suggested by shellcheck. Signed-off-by: Philip Withnall --- gio/completion/gdbus | 2 +- gio/completion/gresource | 8 ++++---- gio/completion/gsettings | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gio/completion/gdbus b/gio/completion/gdbus index cfe87517b..e7c3ad58d 100644 --- a/gio/completion/gdbus +++ b/gio/completion/gdbus @@ -11,7 +11,7 @@ __gdbus() { local IFS=$'\n' local cur="$(_get_cword :)" - local suggestions=$(gdbus complete "${COMP_LINE}" ${COMP_POINT}) + local suggestions="$(gdbus complete "${COMP_LINE}" "${COMP_POINT}")" COMPREPLY=($(compgen -W "$suggestions" -- "$cur")) # Remove colon-word prefix from COMPREPLY items diff --git a/gio/completion/gresource b/gio/completion/gresource index a30c2ade7..915b4ab1c 100644 --- a/gio/completion/gresource +++ b/gio/completion/gresource @@ -9,8 +9,8 @@ __gresource() { local choices coffset section - if [ ${COMP_CWORD} -gt 2 ]; then - if [ ${COMP_WORDS[1]} = --section ]; then + if [ "${COMP_CWORD}" -gt 2 ]; then + if [ "${COMP_WORDS[1]}" = --section ]; then section=${COMP_WORDS[2]} coffset=2 else @@ -36,7 +36,7 @@ __gresource() { ;; sections|list|details|extract) - COMPREPLY=($(compgen -f -- ${COMP_WORDS[${COMP_CWORD}]})) + COMPREPLY=($(compgen -f -- "${COMP_WORDS[${COMP_CWORD}]}")) return 0 ;; esac @@ -45,7 +45,7 @@ __gresource() { 3) 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 ;; diff --git a/gio/completion/gsettings b/gio/completion/gsettings index 98ee2b2c4..1cc4cbac4 100644 --- a/gio/completion/gsettings +++ b/gio/completion/gsettings @@ -9,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 @@ -29,7 +29,7 @@ __gsettings() { 2) case "${COMP_WORDS[$(($coffset+1))]}" in --schemadir) - COMPREPLY=($(compgen -o dirnames -- ${COMP_WORDS[${COMP_CWORD}]})) + COMPREPLY=($(compgen -o dirnames -- "${COMP_WORDS[${COMP_CWORD}]}")) return 0 ;; @@ -37,15 +37,15 @@ __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}]})) + 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 ;; @@ -53,11 +53,11 @@ __gsettings() { 3) 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 ;; @@ -65,7 +65,7 @@ __gsettings() { 4) case "${COMP_WORDS[$(($coffset+2))]}" in set) - range=($(gsettings $schemadir range ${COMP_WORDS[$(($coffset+2))]} ${COMP_WORDS[$(($coffset+3))]} 2> /dev/null)) + range=($(gsettings "$schemadir" range "${COMP_WORDS[$(($coffset+2))]}" "${COMP_WORDS[$(($coffset+3))]}" 2> /dev/null)) case "${range[0]}" in enum) unset range[0] From a7ad2a4c3aee3804cd4a4933d337c6d41c60f6ad Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 14:03:19 +0100 Subject: [PATCH 04/11] completion: Drop unnecessary $ from variables in arithmetic expressions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s not needed, according to shellcheck. Signed-off-by: Philip Withnall --- gio/completion/gdbus | 2 +- gio/completion/gio | 2 +- gio/completion/gresource | 8 ++++---- gio/completion/gsettings | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gio/completion/gdbus b/gio/completion/gdbus index e7c3ad58d..abfb44256 100644 --- a/gio/completion/gdbus +++ b/gio/completion/gdbus @@ -22,7 +22,7 @@ __gdbus() { 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 diff --git a/gio/completion/gio b/gio/completion/gio index 2a27a8c39..4a4f4aff1 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -109,7 +109,7 @@ __gio_location() { __gio() { # Complete subcommands - if (( ${COMP_CWORD} == 1 )); then + if (( COMP_CWORD == 1 )); then 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 diff --git a/gio/completion/gresource b/gio/completion/gresource index 915b4ab1c..fca4be4d2 100644 --- a/gio/completion/gresource +++ b/gio/completion/gresource @@ -20,13 +20,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 ;; @@ -43,9 +43,9 @@ __gresource() { ;; 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 ;; diff --git a/gio/completion/gsettings b/gio/completion/gsettings index 1cc4cbac4..87c3e3356 100644 --- a/gio/completion/gsettings +++ b/gio/completion/gsettings @@ -21,13 +21,13 @@ __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}]}")) return 0 @@ -51,21 +51,21 @@ __gsettings() { ;; 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)) + range=($(gsettings "$schemadir" range "${COMP_WORDS[$((coffset+2))]}" "${COMP_WORDS[$((coffset+3))]}" 2> /dev/null)) case "${range[0]}" in enum) unset range[0] From d3d811f4e54427a2a409dd04c8573a9f30c9143d Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 14:05:04 +0100 Subject: [PATCH 05/11] completion: Split declaration and assignment of variables Having them on the same line masks failure of the subcommand generating the value being assigned. Spotted by shellcheck. Signed-off-by: Philip Withnall --- gio/completion/gdbus | 6 ++++-- gio/completion/gio | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gio/completion/gdbus b/gio/completion/gdbus index abfb44256..fea093271 100644 --- a/gio/completion/gdbus +++ b/gio/completion/gdbus @@ -9,9 +9,11 @@ __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}")" COMPREPLY=($(compgen -W "$suggestions" -- "$cur")) # Remove colon-word prefix from COMPREPLY items diff --git a/gio/completion/gio b/gio/completion/gio index 4a4f4aff1..590dd53ee 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -71,7 +71,8 @@ __gio_location() { local name size type while IFS=$'\t' read name size 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 From b1ef6a125eb63791be4e08f20c7c4b9d60992b15 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 14:06:13 +0100 Subject: [PATCH 06/11] completion: Quote variable dereferences within variable dereferences Otherwise they could get split. Spotted by shellcheck. Signed-off-by: Philip Withnall --- gio/completion/gdbus | 2 +- gio/completion/gio | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gio/completion/gdbus b/gio/completion/gdbus index fea093271..6db3d70fa 100644 --- a/gio/completion/gdbus +++ b/gio/completion/gdbus @@ -21,7 +21,7 @@ __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"} diff --git a/gio/completion/gio b/gio/completion/gio index 590dd53ee..4461dd419 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -47,7 +47,7 @@ __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 From 7ad93a0c95823da1380c65d0eb827c126b590a15 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 14:07:12 +0100 Subject: [PATCH 07/11] completion: Use `read -r` rather then plain `read` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This means that backslashes in the input (which is unlikely, but I guess possible) won’t affect line splitting. Spotted by shellcheck. Signed-off-by: Philip Withnall --- gio/completion/gio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gio/completion/gio b/gio/completion/gio index 4461dd419..aab70f483 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -53,7 +53,7 @@ __gio_location() { # 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 @@ -69,7 +69,7 @@ __gio_location() { local files=() local names=() local name size type - while IFS=$'\t' read name size type; do + while IFS=$'\t' read -r name size type; do # Escape name properly local escaped_name escaped_name="$(printf "%q" "$name")" From 17f0cad2c71f9d288088d17b05258582cdd105e9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 14:08:08 +0100 Subject: [PATCH 08/11] completion: Drop some unused variables Spotted by shellcheck. Signed-off-by: Philip Withnall --- gio/completion/gio | 4 ++-- gio/completion/gresource | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/gio/completion/gio b/gio/completion/gio index aab70f483..2e993ce81 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -68,8 +68,8 @@ __gio_location() { # List files local files=() local names=() - local name size type - while IFS=$'\t' read -r name size type; do + local name type + while IFS=$'\t' read -r name _ type; do # Escape name properly local escaped_name escaped_name="$(printf "%q" "$name")" diff --git a/gio/completion/gresource b/gio/completion/gresource index fca4be4d2..43f48cb9c 100644 --- a/gio/completion/gresource +++ b/gio/completion/gresource @@ -7,11 +7,10 @@ #################################################################################################### __gresource() { - local choices coffset section + local choices coffset if [ "${COMP_CWORD}" -gt 2 ]; then if [ "${COMP_WORDS[1]}" = --section ]; then - section=${COMP_WORDS[2]} coffset=2 else coffset=0 From 6024fb9753527cc7b9cf955643efe2b538351e28 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 14:08:39 +0100 Subject: [PATCH 09/11] completion: Quote argument to unset Otherwise it gets globbed and the wrong thing potentially gets unset. Spotted by shellcheck. Signed-off-by: Philip Withnall --- gio/completion/gsettings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gio/completion/gsettings b/gio/completion/gsettings index 87c3e3356..d84378579 100644 --- a/gio/completion/gsettings +++ b/gio/completion/gsettings @@ -68,7 +68,7 @@ __gsettings() { 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 From 827bca3212f46f97152c94cd0d50af1593b7a607 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 14:09:36 +0100 Subject: [PATCH 10/11] completion: Ignore SC2207 for COMPREPLY assigments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the same justification as in https://gitlab.gnome.org/GNOME/dconf/-/merge_requests/81#note_2083220: it’s hard to get this right, with error handling, in a way which is understandable to people reading it, and which both bash and shellcheck will be happy with. On the assumption that none of the completions generated by any of these utilities will include ‘problematic’ characters (ones which would cause word splitting or globbing in bash), just ignore the shellcheck warnings. Note that I have not actually closely verified that these utilities can’t return ‘problematic’ characters. This means we can enable shellcheck, with fatal warnings, for these scripts, and hence catch future regressions. If someone wants to improve the handling of globbing/word splitting in some/all of these array assignments in future, the shellcheck disables can be removed. Signed-off-by: Philip Withnall --- gio/completion/gapplication | 4 ++++ gio/completion/gdbus | 1 + gio/completion/gio | 1 + gio/completion/gresource | 2 ++ gio/completion/gsettings | 4 ++++ 5 files changed, 12 insertions(+) diff --git a/gio/completion/gapplication b/gio/completion/gapplication index 429b6cf83..ab3929b57 100644 --- a/gio/completion/gapplication +++ b/gio/completion/gapplication @@ -9,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 ;; @@ -16,6 +17,7 @@ __app() { 2) case "${COMP_WORDS[1]}" in launch|action|list-actions) + # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "$(gapplication list-apps)" -- "${COMP_WORDS[2]}")) return 0 ;; @@ -33,6 +35,7 @@ __app() { action) # Word 3 is the action name. This is the only one we can help with. if [ "${COMP_CWORD}" == 3 ]; then + # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "$(gapplication list-actions "${COMP_WORDS[2]}")" -- "${COMP_WORDS[3]}")) return 0 else @@ -42,6 +45,7 @@ __app() { ;; launch) # Filenames... + # shellcheck disable=SC2207 COMPREPLY=($(compgen -A file "${COMP_WORDS[COMP_CWORD]}")) return 0 ;; diff --git a/gio/completion/gdbus b/gio/completion/gdbus index 6db3d70fa..2b18030fa 100644 --- a/gio/completion/gdbus +++ b/gio/completion/gdbus @@ -14,6 +14,7 @@ __gdbus() { local suggestions suggestions="$(gdbus complete "${COMP_LINE}" "${COMP_POINT}")" + # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "$suggestions" -- "$cur")) # Remove colon-word prefix from COMPREPLY items diff --git a/gio/completion/gio b/gio/completion/gio index 2e993ce81..0f0de6b69 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -111,6 +111,7 @@ __gio_location() { __gio() { # Complete subcommands 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 diff --git a/gio/completion/gresource b/gio/completion/gresource index 43f48cb9c..d633ec1b3 100644 --- a/gio/completion/gresource +++ b/gio/completion/gresource @@ -35,6 +35,7 @@ __gresource() { ;; sections|list|details|extract) + # shellcheck disable=SC2207 COMPREPLY=($(compgen -f -- "${COMP_WORDS[${COMP_CWORD}]}")) return 0 ;; @@ -51,6 +52,7 @@ __gresource() { esac local IFS=$'\n' + # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${choices}" -- "${COMP_WORDS[${COMP_CWORD}]}")) } diff --git a/gio/completion/gsettings b/gio/completion/gsettings index d84378579..b2c90b831 100644 --- a/gio/completion/gsettings +++ b/gio/completion/gsettings @@ -29,6 +29,7 @@ __gsettings() { 2) case "${COMP_WORDS[$((coffset+1))]}" in --schemadir) + # shellcheck disable=SC2207 COMPREPLY=($(compgen -o dirnames -- "${COMP_WORDS[${COMP_CWORD}]}")) return 0 ;; @@ -40,6 +41,7 @@ __gsettings() { choices="$(gsettings "$schemadir" list-schemas 2> /dev/null)"$'\n'"$(gsettings "$schemadir" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')" ;; list-schemas) + # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "--print-paths" -- "${COMP_WORDS[${COMP_CWORD}]}")) return 0 ;; @@ -65,6 +67,7 @@ __gsettings() { 4) case "${COMP_WORDS[$((coffset+2))]}" in set) + # shellcheck disable=SC2207 range=($(gsettings "$schemadir" range "${COMP_WORDS[$((coffset+2))]}" "${COMP_WORDS[$((coffset+3))]}" 2> /dev/null)) case "${range[0]}" in enum) @@ -82,6 +85,7 @@ __gsettings() { esac local IFS=$'\n' + # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${choices}" -- "${COMP_WORDS[${COMP_CWORD}]}")) } From e577f16d016df60428652a20ed3af872ce45585a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 16 Apr 2024 14:16:30 +0100 Subject: [PATCH 11/11] tests: Enable shellcheck for bash completion scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These were accidentally left off the list of files checked before, because they don’t have `.sh` suffixes. Signed-off-by: Philip Withnall --- tests/shellcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/shellcheck.sh b/tests/shellcheck.sh index 4f5ce6209..cbef761ff 100755 --- a/tests/shellcheck.sh +++ b/tests/shellcheck.sh @@ -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