[glib: 1/2] completion: Declare variables as local in gio completion script
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] completion: Declare variables as local in gio completion script
- Date: Tue, 5 Jan 2021 16:27:45 +0000 (UTC)
commit 2ca4d865b23e6cd21f9c2f62a451965288421b4f
Author: Philip Withnall <pwithnall endlessos org>
Date: Mon Jan 4 19:14:25 2021 +0000
completion: Declare variables as local in gio completion script
Most variables were, but a few were not declared as local, and hence
leaked into the calling environment every time someone tab-completed the
`gio` command.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Fixes: #2275
gio/completion/gio | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/gio/completion/gio b/gio/completion/gio
index 989befedd..c650475b9 100644
--- a/gio/completion/gio
+++ b/gio/completion/gio
@@ -22,7 +22,8 @@
# Check whether the suggestions have common prefix (i.e. suggestions won't be
# shown and prefix will be completed first)
-__has_common_prefix() {
+__gio_has_common_prefix() {
+ local i
for (( i = 1; i < ${#COMPREPLY[@]}; i++ )); do
if [[ "${COMPREPLY[i-1]:${#cur}:1}" != "${COMPREPLY[i]:${#cur}:1}" ]]; then
return 1 # False
@@ -49,6 +50,7 @@ __gio_location() {
# List volumes and mounts
local mounts=( )
+ local mount
while IFS=$'\n' read mount; do
# Do not care about local mounts
[[ "$mount" =~ ^"file:" ]] && continue
@@ -58,12 +60,13 @@ __gio_location() {
done < <(gio mount -li | sed -n -r 's/^ *(default_location|activation_root)=(.*)$/\2/p' | sort -u)
# Workaround to unescape dir name (e.g. "\ " -> " ")
- declare -a tmp="( ${dir} )"
- unescaped_dir="${tmp[0]}"
+ local -a tmp="( ${dir} )"
+ local unescaped_dir="${tmp[0]}"
# List files
local files=()
local names=()
+ local name size type
while IFS=$'\t' read name size type; do
# Escape name properly
local escaped_name="$(printf "%q" "$name")"
@@ -75,7 +78,7 @@ __gio_location() {
escaped_name="$escaped_name "
fi
- path="$dir$escaped_name"
+ local path="$dir$escaped_name"
# Use only matching paths
if [[ "$path" =~ ^"$cur" ]]; then
@@ -87,7 +90,7 @@ __gio_location() {
COMPREPLY=("${files[@]}" "${mounts[@]}")
# Workaround to show suggestions as basenames only
- if ! __has_common_prefix; then
+ if ! __gio_has_common_prefix; then
COMPREPLY=("${mounts[@]} ${names[@]}")
# Workaround to prevent overwriting suggestions, it adds empty
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]