[Bash-completion-devel] mount label|uuid
gibboris at gmail.com
gibboris at gmail.com
Tue Apr 14 15:16:14 UTC 2009
On Tue, Apr 14, 2009 at 05:27:49PM +0300, Ville Skyttä wrote:
> On Tuesday 14 April 2009, gibboris at gmail.com wrote:
> > Hi,
> > Modified as suggested, tested (but not "heavily") and it seems to work.
> [...]
> > - I postulated uuidgen always output lower-case hex
>
> Why make such assumptions and assumptions in general about the UUID length?
> Why not just look for whitespace like in the suggested:
Of course we can look for spaces, anyway an uuid is 128 bits long, but
the '-' make it a slightly different : so 2 possibilities :
- lower AND upper case, and >=32 and <=36 chars : [a-zA-Z-]\{32,36\}
OR
- [^[:space:]]*
Attachment makes assumption about which solution you prefer ;)
> > > COMPREPLY=( $( compgen -W '$( sed -ne "s/^UUID=\([^[:space:]]*\).*/\1/p"
> > > /etc/fstab )' -- $cur ) )
>
> Also, the leading /UUID/ seems to me as superfluous, i.e. why 'sed -ne
> /UUID/s/^UUID=.../p' instead of simply 'sed -ne s/UUID=.../p' ? (Ditto for
> LABEL.)
I always believed it was a performance gain as it will skip any line without
this pattern and never charge a buffer with more than 5 characters of a
non-matching line but.... I never did tests about that and it's maybe a myth :[
Also I removed the leading ^ as a fstab line mays begin with blank.
Last doubt : adding a leading ^[^#]* to the regexp as, in this world it may
exist some stupid fstab like :
#UUID=foo
/dev/sda1....
or
/dev/sda1 .... 0 1 #UUID=blah
I wish this attachment satisfactory :)
A last thing : why the cygwin and solaris COMPREPLY don't use $(compgen -- $cur) instead of $(grep "^$cur") ?
Raph
-------------- next part --------------
diff --git a/bash_completion b/bash_completion
index 688adbd..f8e9812 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=( $( compgen -W '$(sed -n "s/LABEL=\([^[:space:]]*\).*/\1/p" /etc/fstab)' -- $cur ) )
+ elif [ $prev = -U ]; then
+ COMPREPLY=( $( compgen -W '$(sed -n "s/UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab)' -- $cur ) )
+ 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