Public bug reported:

Binary package hint: bash-completion

When passwordless authentication is setup, scp allows autocompletion of
the nature:

scp host:/home/martin/Doc <TAB>

This appears to be broken in Karmic (Kubuntu anyway) as this line in
/etc/bash_completion.d/ssh causes local expansion of directories:

_expand || return 0

This means that, typing the above expands to /home/martin/Documents on
the LOCAL machine, not on the remote.

My revised version, that now works, looks like this for the _scp
function:

_scp()
{
        local cur userhost path
        COMPREPLY=()

        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"

        # replaced by the above 2 lines
        #cur=`_get_cword ":"`

        ## Removed to avoid local expansion
        #_expand || return 0

        if [[ "$prev" == *:* ]]; then
                # This happens when there is a : in the path
                local IFS=$'\t\n'
                # remove backslash escape from :
                cur=${cur/\\:/:}
                userhost=${COMP_WORDS[COMP_CWORD-2]}
                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' ) )
                return 0
        fi

        [[ "$cur" == */* ]] || _known_hosts -c -a
                local IFS=$'\t\n'
                COMPREPLY=( "${comprep...@]}" $( command ls -aF1d $cur* \
                            2>/dev/null | sed \
                            -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\&/g" \
                            -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
        return 0
}
complete -F _scp $nospace scp

** Affects: bash-completion (Ubuntu)
     Importance: Undecided
         Status: New

-- 
ssh/scp autocompletion broken in Karmic
https://bugs.launchpad.net/bugs/481310
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to