ssh/scp autocompletion broken in Karmic

Bug #481310 reported by Martin Eve
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash-completion (Ubuntu)
New
Undecided
Unassigned
Nominated for Karmic by Shawn Deleurme
Nominated for Lucid by Shawn Deleurme

Bug Description

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=( "${COMPREPLY[@]}" $( command ls -aF1d $cur* \
                            2>/dev/null | sed \
                            -e "s/[][(){}<>\",:;^&!$&=?\`|\\ ']/\\\\&/g" \
                            -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ) )
        return 0
}
complete -F _scp $nospace scp

Revision history for this message
Martin Eve (martineve) wrote :

I have written a succinct patch that appears to fix the issue.

Regards,

Martin

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Patches

Remote bug watches

Bug watches keep track of this bug in other bug trackers.