# 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 { var cur = '', prev = '', words = '', cword = '' _init_completion -n : || return var sm = '', host = '' match $prev { with -t|--types _fstypes return 0 } [[ "$cur" == \\ ]] && set cur = '"/'" if [[ "$cur" == *:* ]] { for sm in [$[type -P showmount]] {,/usr}/{,s}bin/showmount { [[ -x $sm ]] || continue setglobal COMPREPLY = '( '$( compgen -W "$( "$sm" -e ${cur%%:*} | \ awk 'NR>1 {print $1}' )" -- "${cur#*:}" ) ) return 0 } } if [[ "$cur" == //* ]] { set host = $(cur#//) set host = $(host%%/*) if [[ -n $host ]] { setglobal 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 setglobal COMPREPLY = '( '$( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) ) } elif [[ ! -e /etc/fstab ]] { # probably Cygwin setglobal COMPREPLY = '( '$( compgen -W "$( $1 | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) ) } else { # probably BSD setglobal 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