bash-completion: umount support relative path and ~ as home shorthands

Addresses: https://github.com/karelzak/util-linux/issues/703
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2019-01-12 11:14:15 +00:00
parent 1a83c00d88
commit 3ebfc8d370
No known key found for this signature in database
GPG Key ID: 0D46FEF7E61DBB46
1 changed files with 19 additions and 1 deletions

View 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