Add zsh anything.el plugin
[zsh.git] / .zsh / zaw / sources / ssh-hosts.zsh
1 #
2 # zaw-src-ssh-hosts
3 #
4 # Note: .ssh/config must have "HashKnownHosts no" (default) to make known hosts
5 # values work.
6
7 function zaw-src-ssh-hosts(){
8 local -a _global_ssh_known_hosts _global_ssh_known_hosts2 _ssh_known_hosts _ssh_known_hosts2 _etc_hosts _ssh_config_hosts
9 [ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_known_hosts=(${${${(f)"$(< /etc/ssh/ssh_known_hosts)"}%%\ *}%%,*}) 2>/dev/null || _global_ssh_known_hosts=()
10 [ -r /etc/ssh/ssh_known_hosts2 ] && _global_ssh_known_hosts2=(${${${(f)"$(< /etc/ssh/ssh_known_hosts2)"}%%\ *}%%,*}) 2>/dev/null || _global_ssh_known_hosts2=()
11 [ -r "$HOME/.ssh/known_hosts" ] && _ssh_known_hosts=(${${${(f)"$(< ~/.ssh/known_hosts)"}%%\ *}%%,*}) 2>/dev/null || _ssh_known_hosts=()
12 [ -r "$HOME/.ssh/known_hosts2" ] && _ssh_known_hosts=(${${${(f)"$(< ~/.ssh/known_hosts2)"}%%\ *}%%,*}) 2>/dev/null || _ssh_known_hosts2=()
13 [ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
14 [ -r "$HOME/.ssh/config" ] && _ssh_config_hosts=(${${${(@M)${(f)"$(< ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*}) || _ssh_config_hosts=()
15 candidates=(
16 $_global_ssh_known_hosts[@]
17 $_global_ssh_known_hosts2[@]
18 $_ssh_known_hosts[@]
19 $_ssh_known_hosts2[@]
20 $_etc_hosts[@]
21 $_ssh_config_hosts[@]
22 "$HOST"
23 ::1
24 localhost
25 127.0.0.1
26 )
27 candidates=(${(iou)candidates[@]})
28
29 actions=("zaw-callback-ssh-connect" "zaw-callback-append-to-buffer" )
30
31 act_descriptions=("ssh to the host" "append to edit buffer")
32 }
33
34 zaw-register-src -n ssh-hosts zaw-src-ssh-hosts
35
36 function zaw-callback-ssh-connect(){
37 local orig_buffer="${BUFFER}"
38 BUFFER="ssh $1"
39 zle accept-line
40 }