mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-19 13:49:17 +02:00
Merge branch '2275-gio-script-local' into 'master'
completion: Declare variables as local in gio completion script Closes #2275 See merge request GNOME/glib!1839
This commit is contained in:
commit
01b77666bc
@ -22,7 +22,8 @@
|
|||||||
|
|
||||||
# Check whether the suggestions have common prefix (i.e. suggestions won't be
|
# Check whether the suggestions have common prefix (i.e. suggestions won't be
|
||||||
# shown and prefix will be completed first)
|
# shown and prefix will be completed first)
|
||||||
__has_common_prefix() {
|
__gio_has_common_prefix() {
|
||||||
|
local i
|
||||||
for (( i = 1; i < ${#COMPREPLY[@]}; i++ )); do
|
for (( i = 1; i < ${#COMPREPLY[@]}; i++ )); do
|
||||||
if [[ "${COMPREPLY[i-1]:${#cur}:1}" != "${COMPREPLY[i]:${#cur}:1}" ]]; then
|
if [[ "${COMPREPLY[i-1]:${#cur}:1}" != "${COMPREPLY[i]:${#cur}:1}" ]]; then
|
||||||
return 1 # False
|
return 1 # False
|
||||||
@ -49,6 +50,7 @@ __gio_location() {
|
|||||||
|
|
||||||
# List volumes and mounts
|
# List volumes and mounts
|
||||||
local mounts=( )
|
local mounts=( )
|
||||||
|
local mount
|
||||||
while IFS=$'\n' read mount; do
|
while IFS=$'\n' read mount; do
|
||||||
# Do not care about local mounts
|
# Do not care about local mounts
|
||||||
[[ "$mount" =~ ^"file:" ]] && continue
|
[[ "$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)
|
done < <(gio mount -li | sed -n -r 's/^ *(default_location|activation_root)=(.*)$/\2/p' | sort -u)
|
||||||
|
|
||||||
# Workaround to unescape dir name (e.g. "\ " -> " ")
|
# Workaround to unescape dir name (e.g. "\ " -> " ")
|
||||||
declare -a tmp="( ${dir} )"
|
local -a tmp="( ${dir} )"
|
||||||
unescaped_dir="${tmp[0]}"
|
local unescaped_dir="${tmp[0]}"
|
||||||
|
|
||||||
# List files
|
# List files
|
||||||
local files=()
|
local files=()
|
||||||
local names=()
|
local names=()
|
||||||
|
local name size type
|
||||||
while IFS=$'\t' read name size type; do
|
while IFS=$'\t' read name size type; do
|
||||||
# Escape name properly
|
# Escape name properly
|
||||||
local escaped_name="$(printf "%q" "$name")"
|
local escaped_name="$(printf "%q" "$name")"
|
||||||
@ -75,7 +78,7 @@ __gio_location() {
|
|||||||
escaped_name="$escaped_name "
|
escaped_name="$escaped_name "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
path="$dir$escaped_name"
|
local path="$dir$escaped_name"
|
||||||
|
|
||||||
# Use only matching paths
|
# Use only matching paths
|
||||||
if [[ "$path" =~ ^"$cur" ]]; then
|
if [[ "$path" =~ ^"$cur" ]]; then
|
||||||
@ -87,7 +90,7 @@ __gio_location() {
|
|||||||
COMPREPLY=("${files[@]}" "${mounts[@]}")
|
COMPREPLY=("${files[@]}" "${mounts[@]}")
|
||||||
|
|
||||||
# Workaround to show suggestions as basenames only
|
# Workaround to show suggestions as basenames only
|
||||||
if ! __has_common_prefix; then
|
if ! __gio_has_common_prefix; then
|
||||||
COMPREPLY=("${mounts[@]} ${names[@]}")
|
COMPREPLY=("${mounts[@]} ${names[@]}")
|
||||||
|
|
||||||
# Workaround to prevent overwriting suggestions, it adds empty
|
# Workaround to prevent overwriting suggestions, it adds empty
|
||||||
|
Loading…
x
Reference in New Issue
Block a user