From e270eb18e3295e10248680669485d5fa8f64a3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 21 Apr 2010 19:07:17 +0300 Subject: [PATCH] Improve filesystem type completions. --- CHANGES | 8 ++++---- bash_completion | 23 +++++++++++++++++++++++ contrib/findutils | 9 +++++---- contrib/mount | 8 ++++++++ test/lib/completions/find.exp | 6 ++++++ test/lib/completions/mount.exp | 6 ++++++ 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 1bb01f2c..2ffeacaa 100644 --- a/CHANGES +++ b/CHANGES @@ -25,10 +25,10 @@ bash-completion (2.x) * Apply cardctl completion to pccardctl too. * Apply pine completion to alpine too. * Remove many unnecessary short option completions where long ones exist. - * Improve chsh, chgrp, chown, configure, cvs, gkrellm, gzip, iconv, lftp, - look, make, man, mdadm, modprobe, mplayer, mysqladmin, perldoc, rsync, - screen, service, scp, ssh, sshfs, update-alternatives, vncviewer, wget, - yp-tools, and general hostname completions. + * Improve chsh, chgrp, chown, configure, cvs, find, gkrellm, gzip, iconv, + lftp, look, make, man, mdadm, modprobe, mount, mplayer, mysqladmin, + perldoc, rsync, screen, service, scp, ssh, sshfs, update-alternatives, + vncviewer, wget, yp-tools, and general hostname completions. * Add abook and wtf completion, based on work by Raphaƫl Droz. * Add cvsps, dragon, fusermount, jarsigner, k3b, lftpget, pm-utils, rtcwake, pack200, unpack200, pbzip2, pbunzip2, pbzcat, pigz and unpigz completions. diff --git a/bash_completion b/bash_completion index da40cbb0..c73ea1d6 100644 --- a/bash_completion +++ b/bash_completion @@ -950,6 +950,29 @@ _shells() -- "$cur" ) ) } +# This function completes on valid filesystem types +# +_fstypes() +{ + local fss + + if [ -e /proc/filesystems ] ; then + # Linux + fss="$( cut -d$'\t' -f2 /proc/filesystems ) + $( awk '! /\*/ { print $NF }' /etc/filesystems 2>/dev/null )" + else + # Generic + fss="$( awk '/^[ \t]*[^#]/ { print $3 }' /etc/fstab 2>/dev/null ) + $( awk '/^[ \t]*[^#]/ { print $3 }' /etc/mnttab 2>/dev/null ) + $( awk '/^[ \t]*[^#]/ { print $4 }' /etc/vfstab 2>/dev/null ) + $( awk '{ print $1 }' /etc/dfs/fstypes 2>/dev/null ) + $( [ -d /etc/fs ] && command ls /etc/fs )" + fi + + [ -n "$fss" ] && \ + COMPREPLY=( "${COMPREPLY[@]}" $( compgen -W "$fss" -- "$cur" ) ) +} + # Get real command. # - arg: $1 Command # - stdout: Filename of command in PATH with possible symbolic links resolved. diff --git a/contrib/findutils b/contrib/findutils index aa0e9b18..e6726e98 100644 --- a/contrib/findutils +++ b/contrib/findutils @@ -22,10 +22,11 @@ _find() return 0 ;; -fstype) - # this is highly non-portable - [ -e /proc/filesystems ] && - COMPREPLY=( $( compgen -W "$( cut -d$'\t' -f2 /proc/filesystems )" \ - -- "$cur" ) ) + _fstypes + if [[ "$( uname -s )" == *BSD ]] ; then + COMPREPLY=( "${COMPREPLY[@]}" \ + $( compgen -W 'local rdonly' -- "$cur" ) ) + fi return 0 ;; -gid) diff --git a/contrib/mount b/contrib/mount index daf472ce..a22b0788 100644 --- a/contrib/mount +++ b/contrib/mount @@ -82,6 +82,14 @@ _mount() COMPREPLY=() cur=`_get_cword ':'` prev=`_get_pword ':'` + + case $prev in + -t|--types) + _fstypes + return 0 + ;; + esac + [[ "$cur" == \\ ]] && cur="/" if [[ "$cur" == *:* ]]; then diff --git a/test/lib/completions/find.exp b/test/lib/completions/find.exp index 8009fddc..711045c7 100644 --- a/test/lib/completions/find.exp +++ b/test/lib/completions/find.exp @@ -17,6 +17,12 @@ assert_complete_any "find " sync_after_int +assert_complete_any "find -fstype " + + +sync_after_int + + set options [list -amin -anewer -atime -cmin -cnewer -ctime -daystart -depth -empty -exec \ -false -fls -follow -fprint -fprint0 -fprintf -fstype -gid -group -help -ilname -iname \ -inum -ipath -iregex -iwholename -links -lname -ls -maxdepth -mindepth -mmin -mount \ diff --git a/test/lib/completions/mount.exp b/test/lib/completions/mount.exp index b3ee9789..38d93e3b 100644 --- a/test/lib/completions/mount.exp +++ b/test/lib/completions/mount.exp @@ -44,6 +44,12 @@ assert_complete_any "mount " sync_after_int +assert_complete_any "mount -t " + + +sync_after_int + + set test "Check completing nfs mounts" set expected [list /test/path /test/path2 /second/path] set cmd "mount mocksrv:/"