Bug 5429

Summary: "Неправильно" дополняются хосты для ssh/scp
Product: Sisyphus Reporter: Sir Raorn <raorn>
Component: zshAssignee: Fr. Br. George <george>
Status: CLOSED FIXED QA Contact: qa-sisyphus
Severity: enhancement    
Priority: P3 CC: arseny, george, mike
Version: unstable   
Hardware: all   
OS: Linux   
Attachments:
Description Flags
Патч для /usr/share/zsh/Completion/Unix/_ssh
none
/usr/share/zsh/Completion/Unix/_known_hosts
none
/usr/share/zsh/Completion/Unix/_known_hosts none

Description Sir Raorn 2004-11-02 10:41:44 MSK
Имена хостов берутся из /etc/hosts.  Для ssh/scp есть более "доверенный" источник:

10:19 <icct> уважаемые, напомните строчку для zsh чтоб дополняла host в ssh
10:20 <virtuoso> zstyle ':completion:*:hosts' hosts $hosts
10:20 <virtuoso> Где hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\
*}%%,*})
10:20 <virtuoso> Например. :)

Эти команды работают (будучи помещёнными в ~/.zshrc), но хотелось бы из коробки.
(hosts= в одну строку, после '\' идёт пробел)
Comment 1 at@altlinux.org 2005-03-16 21:10:56 MSK
There's a few problems with what you propose.  First, it is to fail when
~/.ssh/known_hosts is nonexistent.  Second, I'm not sure I want to override
hosts style for all commands, not just for ssh and scp.  Anyway, this is going
to get too complicated for /etc/zshrc.  Maybe there should be a separate file,
perhaps in /etc/zshrc.d.
Comment 2 Sir Raorn 2005-03-16 23:02:54 MSK
Separate file должен быть в районе /usr/share/zsh/Completion/Unix/_sshhosts, но
у меня сходу не получилось научить _ssh_hosts брать hosts из
~/.ssh/known_hosts... Будем надеяться, что LATER кто-ньдь что-ньдь сделает. 
Например я разберусь с zsh Completion System...
Comment 3 Sir Raorn 2005-07-13 00:36:31 MSD
LATER наступило.  Патчи в аттачах.
Comment 4 Sir Raorn 2005-07-13 00:37:49 MSD
Created attachment 983 [details]
Патч для /usr/share/zsh/Completion/Unix/_ssh
Comment 5 Sir Raorn 2005-07-13 00:39:30 MSD
Created attachment 984 [details]
/usr/share/zsh/Completion/Unix/_known_hosts

Из ~/.zsh/functions почему-то не autoload'ится.  Почему - пока не понял.
Comment 6 Sir Raorn 2005-07-13 00:43:38 MSD
Смысл такой:

Перебираем ssh_config в составе /etc/ssh/ssh_config /etc/ssh2/ssh_config
/etc/openssh/ssh_config $HOME/.ssh/config $HOME/.ssh/config, из каждого файла
выцепляем параметры:

1. Host с non-pattern аргументом, добавляем к списку вариантов.
2. Global/UserKnownHostsFile, если не определено, используем
/etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 /etc/known_hosts
/etc/known_hosts2 $HOME/.ssh/known_hosts $HOME/.ssh/known_hosts2, и выдираем из
этих файлов хосты.
Comment 7 Sir Raorn 2005-07-13 00:51:58 MSD
Created attachment 985 [details]
/usr/share/zsh/Completion/Unix/_known_hosts
Comment 8 Michael Shigorin 2005-07-13 09:11:42 MSD
о та!
Comment 9 at@altlinux.org 2005-07-18 12:09:20 MSD
$HOME/.ssh/known_hosts listed twice in "for" loop condition.  Did you mean
$HOME/.ssh/known_hosts2?
Comment 10 at@altlinux.org 2005-07-18 12:10:37 MSD
I mean "config2".
-    for f in /etc/ssh/ssh_config /etc/ssh2/ssh_config /etc/openssh/ssh_config
$HOME/.ssh/config $HOME/.ssh/config; do
+    for f in /etc/ssh/ssh_config /etc/ssh2/ssh_config /etc/openssh/ssh_config
$HOME/.ssh/config $HOME/.ssh/config2; do

?
Comment 11 Sir Raorn 2005-07-18 12:23:21 MSD
(In reply to comment #10)
> I mean "config2".

My mistake.  ~/.ssh2/config.

I think these paths must be sanitized.  I've loooked into
/etc/bash_completion(_known_hosts) and added /etc/openssh/.  I'm not sure where
"popular" ssh implementations keeps their configs.  Original list:

Config:
/etc/ssh/ssh_config ~/.ssh/config ~/.ssh2/config

Global known_hosts:
/etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 /etc/known_hosts
/etc/known_hosts2 /etc/ssh2/knownhosts/*pub

User known_hosts:
~/.ssh/known_hosts ~/.ssh/known_hosts2 ~/.ssh2/hostkeys/*pub

knownhosts/hostkeys directories is not supported (yet?).  Also missing
/usr/local/etc/ paths that can be used on *BSD.

P.S. Is there any way to determine ssh config/known_hosts file at runtime?
Comment 12 at@altlinux.org 2005-07-21 23:39:46 MSD
Fixed in zsh-4.3.0-alt0.2.