Use scp remote/local completion functions in sshfs.

This commit is contained in:
Ville Skyttä 2009-12-26 16:20:14 +02:00
parent 000cae95bc
commit b6434541cc
2 changed files with 7 additions and 27 deletions

View File

@ -25,7 +25,7 @@ bash-completion (2.x)
* Apply pine completion to alpine too. * Apply pine completion to alpine too.
* Remove many unnecessary short option completions where long ones exist. * Remove many unnecessary short option completions where long ones exist.
* Improve chsh, configure, cvs, gkrellm, lftp, mdadm, modprobe, mplayer, * Improve chsh, configure, cvs, gkrellm, lftp, mdadm, modprobe, mplayer,
mysqladmin, rsync, screen, service, scp, ssh, update-alternatives, mysqladmin, rsync, screen, service, scp, ssh, sshfs, update-alternatives,
vncviewer, and general hostname completions. vncviewer, and general hostname completions.
* Add abook and wtf completion, based on work by Raphaël Droz. * Add abook and wtf completion, based on work by Raphaël Droz.
* Add jarsigner, k3b, lftpget, pm-utils, pack200 and unpack200 completions. * Add jarsigner, k3b, lftpget, pm-utils, pack200 and unpack200 completions.

View File

@ -1,6 +1,6 @@
# sshfs(1) completion # sshfs(1) completion
have sshfs && have ssh && have sshfs &&
_sshfs() _sshfs()
{ {
local cur userhost path local cur userhost path
@ -10,36 +10,16 @@ _sshfs()
_expand || return 0 _expand || return 0
# things we want to backslash escape if [[ "$cur" == *:* ]] && type _scp_remote_files &>/dev/null ; then
local esc="[][(){}<>\",:;^&\!$=?\`|\\ ']" _scp_remote_files -d
# unlike scp and rsync, sshfs works with 1 backslash instead of 3
if [[ "$cur" == *:* ]]; then COMPREPLY=( "${COMPREPLY[@]//\\\\\\/\\}" )
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 return 0
fi fi
[[ "$cur" == */* ]] || _known_hosts_real -c -a "$cur" [[ "$cur" == */* ]] || _known_hosts_real -c -a "$cur"
# This approach is used instead of _filedir to get a space appended type _scp_local_files &>/dev/null && _scp_local_files -d
# 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 return 0
} && } &&