From: Sami Kerola Date: Sat, 12 Jan 2019 11:14:15 +0000 (+0000) Subject: bash-completion: umount support relative path and ~ as home shorthands X-Git-Tag: v2.34-rc1~161 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3ebfc8d370d21c875cde325532f580acb6250e3d;p=thirdparty%2Futil-linux.git bash-completion: umount support relative path and ~ as home shorthands Addresses: https://github.com/karelzak/util-linux/issues/703 Signed-off-by: Sami Kerola --- diff --git a/bash-completion/umount b/bash-completion/umount index 496474a9b6..7fc2bd3765 100644 --- a/bash-completion/umount +++ b/bash-completion/umount @@ -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