Split sshfs from contrib/ssh to contrib/sshfs.

This commit is contained in:
Ville Skyttä 2009-12-24 16:18:27 +02:00
parent e308b07526
commit e0acaf8ed2
4 changed files with 58 additions and 1 deletions

View File

@ -48,6 +48,7 @@ bash-completion (2.x)
* Turn on -o filenames in _filedir on bash >= 4. * Turn on -o filenames in _filedir on bash >= 4.
* Deprecate modules completion, upstream modules >= 3.2.7 ships one. * Deprecate modules completion, upstream modules >= 3.2.7 ships one.
* Protect grep invocations from user aliases (Alioth: 312143). * Protect grep invocations from user aliases (Alioth: 312143).
* Split sshfs completion from contrib/ssh into contrib/sshfs.
[ Freddy Vulto ] [ Freddy Vulto ]
* Added _get_pword() helper function, thanks to Sung Pae (Alioth: #312030) * Added _get_pword() helper function, thanks to Sung Pae (Alioth: #312030)

View File

@ -123,6 +123,7 @@ bashcomp_DATA = contrib/abook \
contrib/smartctl \ contrib/smartctl \
contrib/snownews \ contrib/snownews \
contrib/ssh \ contrib/ssh \
contrib/sshfs \
contrib/strace \ contrib/strace \
contrib/svk \ contrib/svk \
contrib/sysctl \ contrib/sysctl \

View File

@ -299,6 +299,7 @@ _scp()
[[ "$cur" == */* ]] || _known_hosts_real -c -a -F "$configfile" "$cur" [[ "$cur" == */* ]] || _known_hosts_real -c -a -F "$configfile" "$cur"
fi fi
# This approach is used instead of _filedir to get a space appended # This approach is used instead of _filedir to get a space appended
# after local file/dir completions, and -o nospace retained for others. # after local file/dir completions, and -o nospace retained for others.
local IFS=$'\t\n' local IFS=$'\t\n'
@ -308,7 +309,7 @@ _scp()
return 0 return 0
} }
complete -F _scp -o nospace scp sshfs complete -F _scp -o nospace scp
# ssh-copy-id(1) completion # ssh-copy-id(1) completion
# #

54
contrib/sshfs Normal file
View File

@ -0,0 +1,54 @@
# sshfs(1) completion
have sshfs && have ssh &&
_sshfs()
{
local cur userhost path
COMPREPLY=()
cur=`_get_cword ":"`
_expand || return 0
# things we want to backslash escape
local esc="[][(){}<>\",:;^&\!$=?\`|\\ ']"
if [[ "$cur" == *:* ]]; then
local IFS=$'\t\n'
# remove backslash escape from the first colon
cur=${cur/\\:/:}
userhost=${cur%%?(\\):*}
path=${cur#*:}
# unescape (3 backslashes to 1 for chars we escaped)
path=$( sed -e 's/\\\\\\\('$esc'\)/\\\1/g' <<<"$path" )
if [ -z "$path" ]; then
# default to home dir of specified user on remote host
path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
fi
# escape spaces; remove executables, aliases, pipes and sockets;
# add space at end of file names
COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
command ls -aF1d "$path*" 2>/dev/null | \
sed -e 's/'$esc'/\\\\\\&/g' -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
return 0
fi
[[ "$cur" == */* ]] || _known_hosts_real -c -a "$cur"
# This approach is used instead of _filedir to get a space appended
# after local file/dir completions, and -o nospace retained for others.
local IFS=$'\t\n'
COMPREPLY=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* 2>/dev/null | \
sed -e "s/$esc/\\\\&/g" -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
return 0
} &&
complete -F _sshfs -o nospace sshfs
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh