-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh_handler
executable file
·55 lines (41 loc) · 1017 Bytes
/
ssh_handler
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
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# SSH Handler
# Handles ssh:// links using.
#
# Usage:
# 1. Place the file in ~/bin/ssh_handler
# 2. Set it as a protocol handler in your browser.
#
# Firefox:
# network.protocol-handler.external.ssh=true
# network.protocol-handler.app.ssh=~/bin/ssh_handler
notifier=/usr/bin/notify-send
terminal=/usr/bin/gnome-terminal
netcat=/bin/nc
timeout=1
notify_summary="SSH Handler"
notify() {
if [ -x ${notifier} ]; then
${notifier} "${notify_summary}" "$@"
else
echo "${notify_summary}: $@"
fi
}
test_connection() {
[ "$protocol" = 'ssh' ] && port=22
message=`${netcat} -w ${timeout} -z ${hostname} ${port} 2>&1`
ret_val=$?
if [ $ret_val -ne 0 ]; then
notify "Could not connect to ${hostname}: ${message}"
exit 1
fi
}
protocol=`echo $1 | cut -d: -f1`
hostname=`echo $1 | cut -d/ -f3`
test_connection
if [ "${protocol}" != "ssh" ]; then
notify "Invalid protocol: ${protocol}"
exit 1
fi
notify "Connecting to ${hostname}"
${terminal} -e "${protocol} ${hostname}" &