[Bash-completion-devel] mount label|uuid
gibboris at gmail.com
gibboris at gmail.com
Sun Apr 12 12:24:51 UTC 2009
Hello,
attached : a small patch to make mount attemps to complete with
the label or the uuid when given the -L or -U switch.
Raph
-------------- next part --------------
diff --git a/bash_completion b/bash_completion
index 688adbd..a45944f 100644
--- a/bash_completion
+++ b/bash_completion
@@ -855,11 +855,12 @@ complete -F _umount $dirnames umount
#
_mount()
{
- local cur i sm host
+ local cur i sm host prev
COMPREPLY=()
cur=`_get_cword`
[[ "$cur" == \\ ]] && cur="/"
+ prev=${COMP_WORDS[COMP_CWORD-1]}
for i in {,/usr}/{,s}bin/showmount; do [ -x $i ] && sm=$i && break; done
@@ -884,8 +885,14 @@ _mount()
| grep "^$cur" ) )
else
# probably Linux
- COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \
+ if [ $prev = -L ]; then
+ COMPREPLY=( $( sed -n "/LABEL/s/^LABEL=\($cur[0-9a-z_]*\).*/\1/Ip" /etc/fstab ) )
+ elif [ $prev = -U ]; then
+ COMPREPLY=( $( sed -n "/LABEL/s/^UUID=\($cur[0-9a-f-]\{,36\}\).*/\1/Ip" /etc/fstab ) )
+ else
+ COMPREPLY=( $( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' \
/etc/fstab | grep "^$cur" ) )
+ fi
fi
return 0
More information about the Bash-completion-devel
mailing list