--- bash_completion~ 2006-03-01 17:20:18.000000000 +0100 +++ bash_completion 2008-04-14 14:51:13.000000000 +0200 @@ -2574,23 +2574,30 @@ _expand || return 0 if [[ "$cur" == *:* ]]; then - # remove backslash escape from : - cur=${cur/\\:/:} - userhost=${cur%%?(\\):*} - path=${cur#*:} - # unescape spaces - path=${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) + # if $COMP_SCP_REMOTE is not null, 'scp' will + # complete on remote host path (requires + # passwordless access to the remote host) + if [ -n "${COMP_SCP_REMOTE:-}" ]; then + # remove backslash escape from : + cur=${cur/\\:/:} + userhost=${cur%%?(\\):*} + path=${cur#*:} + # unescape spaces + path=${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/[][(){}<>",:;^&!$&=?`|\ ]/\\\\\\&/g' \ + -e 's/[*@|=]$//g' \ + -e 's/[^\/]$/& /g'\ + -e 's/^/'$userhost:'/' ) ) + return 0 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/[][(){}<>",:;^&!$&=?`|\ ]/\\\\\\&/g' \ - -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) ) - return 0 fi [[ "$cur" == */* ]] || _known_hosts -c -a