3

Lets say, I have one file in current directory, test.txt and I want to transfer it using scp to remote server.

When I use completion, ie:

scp -rp test<TAB>

instead of completing the rest of the filename for me, zsh completion offers:

scp -rp test<TAB>
test.txt
testuser

testuser happens to be local user on my system. Why would zsh completion complete local user, when I am connecting to remote server ?

That seems like a useless and stupid rule.

scp is using same completion file as ssh /usr/share/zsh/functions/Completion/Unix/_ssh, and ssh command has the same behavior, although in case of ssh it is less annoying, since ssh is not supposed to complete local filenames.

How can I modify the completion rules for scp so that it only offers local filenames, not local users?

UPDATE FOR BOUNTY

The accepted solution works for scp, but the problem still persist for ssh. When I want to connect to myserver.domain.org and use completion:

ssh m<TAB>

the completion system offers myserver.domain.org (which is desired), but also local users man and messagebus, which is idiotic.

How can I change the completion system for ssh/scp so that instead of completing all local users from /etc/passwd, I can specify (hardcoded) list of users that I want to complete?

So, in other words: I don't want to disable user completion for ssh, as the accepted answer does for scp. But I want to provide my own list of users that will be completed, instead using all local users from /etc/passwd

0

1 Answer 1

2
+100
zstyle ':completion:*:scp:*' tag-order '! users'

This tells the completion system that, for scp, do not try to complete users unless no other completions can be found. (See http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-tag_002dorder_002c-completion-style)


To specify a list of the only user names that should be completed when using ssh:

zstyle ':completion:*:ssh:*' users alice bob carol

(See http://zsh.sourceforge.net/Doc/Release/Completion-System.html#index-users_002c-completion-style)

4
  • thank you. That works. Jun 17, 2020 at 11:25
  • @400theCat I updated my answer for the bounty. Aug 3, 2020 at 13:06
  • 1
    thank you. The zstyle rule for ssh works beautifully. Aug 3, 2020 at 16:46
  • @400theCat So, do I get the bounty? 🙂 Aug 5, 2020 at 10:20

You must log in to answer this question.

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