# mount(8) completion -*- shell-script -*- if [[ $OSTYPE == *linux* ]] { source "$BASH_SOURCE.linux" return } # This will pull a list of possible mounts out of # /etc/{,v}fstab, unless the word being completed contains a ':', which # would indicate the specification of an NFS server. In that case, we # query the server for a list of all available exports and complete on # that instead. # proc _mount { local cur prev words cword _init_completion -n : || return local sm host case (prev) { -t|--types { _fstypes return 0 } } [[ "$cur" == \\ ]] && setvar cur = ""/"" if [[ "$cur" == *:* ]] { for sm in "$(type -P showmount)" {,/usr}/{,s}bin/showmount { [[ -x $sm ]] || continue setvar COMPREPLY = ''( $( compgen -W "$( "$sm" -e ${cur%%:*} | \ awk 'NR>1 {print $1}' )" -- "${cur#*:}" ) ) return 0 } } if [[ "$cur" == //* ]] { setvar host = ${cur#//} setvar host = ${host%%/*} if [[ -n $host ]] { setvar COMPREPLY = ''( $( compgen -P "//$host" -W \ "$( smbclient -d 0 -NL $host 2>/dev/null | sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' | sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|/\1|p' )" \ -- "${cur#//$host}" ) ) } } elif [[ -r /etc/vfstab ]] { # Solaris setvar COMPREPLY = ''( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) ) } elif [[ ! -e /etc/fstab ]] { # probably Cygwin setvar COMPREPLY = ''( $( compgen -W "$( $1 | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) ) } else { # probably BSD setvar COMPREPLY = ''( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab )" -- "$cur" ) ) } } && complete -F _mount -o default -o dirnames mount # ex: ts=4 sw=4 et filetype=sh