-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathssh-host
executable file
·42 lines (36 loc) · 926 Bytes
/
ssh-host
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
#
help() {
echo 'usage: ssh-host [host]'
echo
echo ' Host lookup inside ~/.ssh/config. If no host'
echo ' is given then output the whole ~/.ssh/config file.'
echo
echo ' This script is most useful together with bash'
echo ' completion:'
echo
echo ' _ssh_host()'
echo ' {'
echo ' local cur prev words cword'
echo ' _init_completion -n = || return'
echo ' _known_hosts_real -a -F ~/.ssh/config "$cur"'
echo ' } && complete -F _ssh_host ssh-host'
echo
exit 1
}
[ "$1" == "--help" ] && help
[ "$1" == "" ] && cat ~/.ssh/config
host="$1"
IFS=$'\n'
matched=no
for i in `cat ~/.ssh/config`
do
if [ "$matched" == "yes" ]; then
if [[ "$i" =~ ^HostName\ ]]; then
echo "$i" | sed 's/HostName *//'
break
fi
elif [[ "$i" =~ ^Host\ *$host ]]; then
matched=yes
fi
done