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