diff --git a/gio/completion/gio b/gio/completion/gio index 86a90e585..63d3a1279 100644 --- a/gio/completion/gio +++ b/gio/completion/gio @@ -43,20 +43,19 @@ __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 - 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 -l | sed -n -r 's/^ *Mount\([0-9]+\): .* -> (.*)$/\1/p') - 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} )"