Presumably this is a feature provided by some plugin I have enabled in my oh-my-zsh setup (I have been using zsh for many years now).

I noticed ever since I added my public key to the server (now I can SSH to the server without entering a password), when I compose a scp command in my shell I am actually able to tab-complete remote file paths!


$ diff <(scp Remoteuser@remote.domain.net:/var/www/html/

I hit tab and it just works! (as for what i am trying to accomplish with the command itself, I am going to use scp to "copy" to stdout, and feed that as a file to diff. This way I can see the exact changes I deploy to the server prior to running rsync)

I'm curious about what are the pieces that make this work so well. Is it something built into scp that was integrated with z shell? Or something else?


Oooh, I found an explanation.

To quote the relevant part:

The zsh shell comes with (more than one) great feature(s), such as remote tabcompletion. If you for example want to copy a file over scp, simply hit tab at any part of the filename on the remote host. zsh is able to establish an ssh session on the background, and fetch the related information for you, so you can tabcomplete trough the remote files.

The post goes on to show some zstyle declarations that achieve the completion, but I would strongly suggest using a zsh package such as the aforementioned oh-my-zsh to get this stuff maintained by the OSS community for you.

Something seemingly relevant, as seen on my system in my .oh-my-zsh dir:

$ ack scp 
85:zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%
[# ]*}//,/ })'

  • Amazing!! Is this feature exclusive to zsh. Is it possible in bash. – shivams May 17 '15 at 16:08
  • 1
    @shivams this may be relevant for your bash needs. It does seem like setting up oh-my-zsh is just a lot easier, plus zsh is just really nice. I think if you really care about it, though, there isn't much that zsh can do that bash can't (and the reverse is certainly true too). Simply a matter of how much work you're willing to put into it. – Steven Lu May 17 '15 at 17:32
  • 7
    @shivams For me it's always Just Worked in bash -- I just hit "tab" instinctively one day in an scp command and was quite surprised to see that it autocompleted! Googling around, it looks as though you need to install the bash-completion package if you don't have it already. This unix.se question is relevant. – Pont May 17 '15 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.