]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - bash-completion/umount
bash-completion: umount support relative path and ~ as home shorthands
[thirdparty/util-linux.git] / bash-completion / umount
index 496474a9b614e5daad7e107b2d0f3d5766ab2035..7fc2bd3765af3073a2a3967af77cb8143d99c416 100644 (file)
@@ -51,7 +51,25 @@ _umount_module()
 
        local oldifs=$IFS
        IFS=$'\n'
-       COMPREPLY=( $( compgen -W '$(findmnt -lno TARGET | sed "s/\([[:blank:]]\)/\\\\\1/g")' -- "$cur" ) )
+       COMPREPLY=( $( compgen -W "$(findmnt -lno TARGET | awk \
+               '{
+                       if ($0 ~ ENVIRON["HOME"]) {
+                               homeless = $0
+                               homeless = gensub(ENVIRON["HOME"], "\\\\~", "g", homeless)
+                               homeless = gensub(/(\s)/, "\\\\\\1", "g", homeless)
+                               print homeless
+                       }
+                       if ($0 ~ ENVIRON["PWD"]) {
+                               reldir = $0
+                               reldir = gensub(ENVIRON["PWD"]"/", "", "g", reldir)
+                               reldir = gensub(/(\s)/, "\\\\\\1", "g", reldir)
+                               print "./" reldir
+                               print reldir
+                       }
+                       gsub(/\s/, "\\\\&")
+                       print $0
+               }'
+       )" -- "$cur" ) )
        IFS=$oldifs
 }
 complete -F _umount_module umount