2

I have a debian system on which my bash tab completion has a weird behavior. When I write a command like scp file.tgz remoteServer:/home/remoteU and hit tab it will complete to scp file.tgz /home/remoteUser killing the host reference. This happens to me for any command ssh related command referencing a remote directory like this.

I already checked my bash completion configuration but couldn't find anything related to deleting test before a colon as this is the character I suspect to be causing the behavior. Also interresting enough the remote system will first be queried for the correct directory.

Any suggestions?

3
  • Yes, it looks wrong. However, what are you expecting the tab completion to complete? A directory on the remote server? To get the pathname of that directory, bash would have to connect to the server and investigate the path. Also, to access the home directory of the user that you connect as, you don't have to go the long way to specify the absolute path. Any relative path would be relative to the home directory of the user.
    – Kusalananda
    Commented Sep 7, 2018 at 8:07
  • 2
    Psst! Kusalananda! Connecting to the remote server and listing the directories is what the Z shell actually does when completing such a command, so this is not a wholly unreasonable expectation.
    – JdeBP
    Commented Sep 7, 2018 at 8:33
  • @Kusalananda I know that there needs to be a connection established and I know that you start via ssh in the users home directory. But first of all it could be that I log in as root or any other user and second this is an abstracted example. It may be another directory then the home directory.
    – Dero
    Commented Sep 7, 2018 at 10:04

1 Answer 1

1

Add this line into your .bashrc to exclude the colon from the COMP_WORDBREAKS.

COMP_WORDBREAKS=${COMP_WORDBREAKS//:}

That's trimming according to this function in the source-code:

__ltrim_colon_completions()
{
    if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
        # Remove colon-word prefix from COMPREPLY items
        local colon_word=${1%"${1##*:}"}
        local i=${#COMPREPLY[*]}
        while [[ $((--i)) -ge 0 ]]; do
            COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
        done
    fi
}
2
  • I tried adding this to my .bashrc without success. I also commented the code from that function with the same result. I will check if there is something in the ssh bash completion definition file that may cause this.
    – Dero
    Commented Sep 7, 2018 at 10:12
  • Turns out I needed to do the exact oposite in my case. The SSH completion script returns a list of remote files. Without the colon to be listed as word break character a values from COMPREPLY will be taken as whole word, trimming the hostname.
    – Dero
    Commented Sep 7, 2018 at 10:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .