diff --git a/gio/completion/gsettings b/gio/completion/gsettings index ea727ef10..bfa7a4bbc 100644 --- a/gio/completion/gsettings +++ b/gio/completion/gsettings @@ -26,13 +26,16 @@ #################################################################################################### __gsettings() { - local choices coffset schemadir="" gsettings_binary + local choices coffset schemadir=() gsettings_binary gsettings_binary="$1" 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]}") + # The eval complexity is needed to perform correct tilde expansion + # The array is needed to ensure we can keep it expanding to either zero + # or one option in the commands below, while keeping quoting correct. + # See https://www.shellcheck.net/wiki/SC2086 + schemadir=("--schemadir" "$(eval "echo ${COMP_WORDS[2]}")") coffset=2 else coffset=0 @@ -58,7 +61,7 @@ __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_binary" "$schemadir" list-schemas 2> /dev/null)"$'\n'"$("$gsettings_binary" "$schemadir" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')" + choices="$("$gsettings_binary" "${schemadir[@]}" list-schemas 2> /dev/null)"$'\n'"$("$gsettings_binary" "${schemadir[@]}" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')" ;; list-schemas) # shellcheck disable=SC2207 @@ -67,7 +70,7 @@ __gsettings() { ;; get|range|set|reset|writable|monitor|describe) - choices="$("$gsettings_binary" "$schemadir" list-schemas 2> /dev/null | sed -e 's.$. .')"$'\n'"$("$gsettings_binary" "$schemadir" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')" + choices="$("$gsettings_binary" "${schemadir[@]}" list-schemas 2> /dev/null | sed -e 's.$. .')"$'\n'"$("$gsettings_binary" "${schemadir[@]}" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')" ;; esac ;; @@ -75,11 +78,11 @@ __gsettings() { 3) case "${COMP_WORDS[$((coffset+1))]}" in set) - choices="$("$gsettings_binary" "$schemadir" list-keys "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null | sed -e 's.$. .')" + choices="$("$gsettings_binary" "${schemadir[@]}" list-keys "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null | sed -e 's.$. .')" ;; get|range|reset|writable|monitor|describe) - choices="$("$gsettings_binary" "$schemadir" list-keys "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null)" + choices="$("$gsettings_binary" "${schemadir[@]}" list-keys "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null)" ;; esac ;; @@ -88,7 +91,7 @@ __gsettings() { case "${COMP_WORDS[$((coffset+2))]}" in set) # shellcheck disable=SC2207 - range=($("$gsettings_binary" "$schemadir" range "${COMP_WORDS[$((coffset+2))]}" "${COMP_WORDS[$((coffset+3))]}" 2> /dev/null)) + range=($("$gsettings_binary" "${schemadir[@]}" range "${COMP_WORDS[$((coffset+2))]}" "${COMP_WORDS[$((coffset+3))]}" 2> /dev/null)) case "${range[0]}" in enum) unset 'range[0]'