2011-11-01 22:14:45 +02:00
|
|
|
# mount(8) completion -*- shell-script -*-
|
2011-11-19 23:06:56 +03:00
|
|
|
|
|
|
|
if [[ $OSTYPE == *linux* ]]; then
|
|
|
|
. "$BASH_SOURCE.linux"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2011-11-01 22:14:45 +02:00
|
|
|
# This will pull a list of possible mounts out of
|
2010-01-02 10:35:18 +02:00
|
|
|
# /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.
|
|
|
|
#
|
|
|
|
_mount()
|
|
|
|
{
|
2011-04-20 22:42:55 +03:00
|
|
|
local cur prev words cword
|
|
|
|
_init_completion -n : || return
|
2010-01-02 10:35:18 +02:00
|
|
|
|
2011-04-20 22:42:55 +03:00
|
|
|
local sm host
|
2010-04-21 19:07:17 +03:00
|
|
|
|
|
|
|
case $prev in
|
|
|
|
-t|--types)
|
|
|
|
_fstypes
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2010-01-02 10:35:18 +02:00
|
|
|
[[ "$cur" == \\ ]] && cur="/"
|
|
|
|
|
2010-01-24 19:43:16 +02:00
|
|
|
if [[ "$cur" == *:* ]]; then
|
2010-02-02 11:17:33 +02:00
|
|
|
for sm in "$(type -P showmount)" {,/usr}/{,s}bin/showmount; do
|
2011-11-09 23:28:11 +02:00
|
|
|
[[ -x $sm ]] || continue
|
2010-01-26 23:17:48 +02:00
|
|
|
COMPREPLY=( $( compgen -W "$( "$sm" -e ${cur%%:*} | \
|
2010-01-24 19:43:16 +02:00
|
|
|
awk 'NR>1 {print $1}' )" -- "${cur#*:}" ) )
|
|
|
|
return 0
|
|
|
|
done
|
|
|
|
fi
|
2010-01-02 10:35:18 +02:00
|
|
|
|
2010-01-24 19:43:16 +02:00
|
|
|
if [[ "$cur" == //* ]]; then
|
2010-01-02 10:35:18 +02:00
|
|
|
host=${cur#//}
|
|
|
|
host=${host%%/*}
|
2011-11-09 23:28:11 +02:00
|
|
|
if [[ -n $host ]]; then
|
2010-01-02 10:35:18 +02:00
|
|
|
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}" ) )
|
|
|
|
fi
|
2011-11-09 23:28:11 +02:00
|
|
|
elif [[ -r /etc/vfstab ]]; then
|
2010-01-02 10:35:18 +02:00
|
|
|
# Solaris
|
|
|
|
COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) )
|
2011-11-09 23:28:11 +02:00
|
|
|
elif [[ ! -e /etc/fstab ]]; then
|
2010-01-02 10:35:18 +02:00
|
|
|
# probably Cygwin
|
|
|
|
COMPREPLY=( $( compgen -W "$( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) )
|
|
|
|
else
|
2012-12-04 18:40:51 +04:00
|
|
|
# probably BSD
|
|
|
|
COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($2 ~ /\//) print $2}' /etc/fstab )" -- "$cur" ) )
|
2010-01-02 10:35:18 +02:00
|
|
|
fi
|
|
|
|
} &&
|
|
|
|
complete -F _mount -o default -o dirnames mount
|
|
|
|
|
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|