From 3a1492ec4f3399f16a47733feffc2003287f9e4f Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Thu, 3 Oct 2019 14:44:57 +0200 Subject: [PATCH 1/3] gio: Fix completion of URIs without hostname part Currently, "gio list file:///h" doesn't complete "file:///home" because the result of "dirname file:///h" is not "file:///" but "file:/", which breaks the consequent logic. Let's subtract basename from the path in order to workaround this issue. --- gio/completion/gio | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gio/completion/gio b/gio/completion/gio index 86a90e585..1e6ef7e8d 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -43,7 +43,8 @@ __gio_location() { if [[ $cur =~ "/"$ ]]; then dir="$cur" elif [[ $cur =~ "/" ]]; then - dir="$(dirname "$cur")/" + # Subtract basename because dirname cmd doesn't work well with schemes + dir=${cur%$(basename "$cur")} fi # List daemon mounts, just if dir is not specified, or looks like scheme From 8bc52105ef1dc298db7094962b732e03adc260fd Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Thu, 3 Oct 2019 14:58:52 +0200 Subject: [PATCH 2/3] gio: Complete also activation roots of volumes Currently, "gio mount google-drive" isn't completed even though that volume exists for google-drive://oholy@redhat.com/. Let's use "gio mount -li" output to complete also activation roots of volumes. --- gio/completion/gio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gio/completion/gio b/gio/completion/gio index 1e6ef7e8d..33c0f5bdd 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -47,7 +47,7 @@ __gio_location() { dir=${cur%$(basename "$cur")} fi - # List daemon mounts, just if dir is not specified, or looks like scheme + # List mounts and volumes, just if dir is not specified, or looks like scheme local mounts=() if [[ $dir == "" ]] || [[ $dir =~ ":"$ && ! $dir =~ "/" ]]; then while IFS=$'\n' read mount; do @@ -56,7 +56,7 @@ __gio_location() { # Use only matching mounts [[ "$mount" =~ ^"$cur" && "$mount" != "$cur" ]] && mounts+=("$mount") - done < <(gio mount -l | sed -n -r 's/^ *Mount\([0-9]+\): .* -> (.*)$/\1/p') + done < <(gio mount -li | sed -n -r 's/^ *(default_location|activation_root)=(.*)$/\2/p' | sort -u) fi # Workaround to unescape dir name (e.g. "\ " -> " ") From b3bf1e263e363da24bc6309a768bb6021ac92f5f Mon Sep 17 00:00:00 2001 From: Ondrej Holy Date: Thu, 3 Oct 2019 15:09:56 +0200 Subject: [PATCH 3/3] gio: Always include mounts in the results Mounts are currently completed only if the prefix looks like scheme, however, this doesn't work well if the mounts have also path component. Let's always include them to fix this issue. The mounts are cached by the volume monitors, so it should not significantly affect the performance. --- gio/completion/gio | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/gio/completion/gio b/gio/completion/gio index 33c0f5bdd..63d3a1279 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -47,17 +47,15 @@ __gio_location() { dir=${cur%$(basename "$cur")} fi - # List mounts and volumes, just if dir is not specified, or looks like scheme - local mounts=() - if [[ $dir == "" ]] || [[ $dir =~ ":"$ && ! $dir =~ "/" ]]; then - while IFS=$'\n' read mount; do - # Do not care about local mounts - [[ "$mount" =~ ^"file:" ]] && continue + # List volumes and mounts + local mounts=( ) + while IFS=$'\n' read mount; do + # Do not care about local mounts + [[ "$mount" =~ ^"file:" ]] && continue - # Use only matching mounts - [[ "$mount" =~ ^"$cur" && "$mount" != "$cur" ]] && mounts+=("$mount") - done < <(gio mount -li | sed -n -r 's/^ *(default_location|activation_root)=(.*)$/\2/p' | sort -u) - fi + # Use only matching mounts + [[ "$mount" =~ ^"$cur" && "$mount" != "$cur" ]] && mounts+=("$mount") + 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} )"