Commit 01b77666 authored by Philip Withnall's avatar Philip Withnall
Browse files

Merge branch '2275-gio-script-local' into 'master'

completion: Declare variables as local in gio completion script

Closes #2275

See merge request !1839
parents d752d3be 2ca4d865
Pipeline #244103 failed with stages
in 65 minutes and 5 seconds
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment