Fix scp completion for paths containing other backslash escaped chars besides spaces.

This commit is contained in:
Ville Skyttä 2009-11-28 12:23:38 +02:00
parent ff0f741dcf
commit 3a44188d52

View File

@ -172,12 +172,14 @@ _scp()
if [[ "$cur" == *:* ]]; then
local IFS=$'\t\n'
# things we want to backslash escape
local esc="[][(){}<>\",:;^&\!$=?\`|\\ ']"
# remove backslash escape from :
cur=${cur/\\:/:}
userhost=${cur%%?(\\):*}
path=${cur#*:}
# unescape spaces
path=${path//\\\\ / }
# 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)
@ -186,7 +188,7 @@ _scp()
# add space at end of file names
COMPREPLY=( $( ssh -o 'Batchmode yes' $userhost \
command ls -aF1d "$path*" 2>/dev/null | \
sed -e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\\\\\\\\\&/g" \
sed -e "s/$esc/\\\\\\\\\\\\&/g" \
-e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
return 0
fi