-
Notifications
You must be signed in to change notification settings - Fork 0
/
sshmenu
executable file
·82 lines (66 loc) · 1.82 KB
/
sshmenu
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
#
# sshmenu
usage() {
base=$(basename "$0")
cat >&2 << EOF
Usage:
$ $base
EOF
[ $# -eq 0 ] || exit "$1"
}
width() {
ps=$(txtw -f "$FONT" "$PROMPT")
char="$(printf '%s\n' "$hosts" | wc -L)"
W=$(echo "($ps + $char * 4.9 + 8) / 1" | bc)
}
menu() {
# menu geometry
X0="$(mattr x "$PFM")"
Y0="$(mattr y "$PFM")"
mouse="$(wmp)"
X=$((${mouse% *} - X0 - 20))
Y=$((${mouse#* } - Y0 - 20))
}
center() {
width
H=$((nHosts * FH))
# finding x y cords for centering
if [ "$PFW" = "0x00000000" ]; then
X=$(($(mattr w "$PFM")/2 - W/2 - 10))
Y=$(($(mattr h "$PFM")/2 - H/2 - 10))
else
X0="$(mattr x "$PFM")"
Y0="$(mattr y "$PFM")"
X=$(($(wattr x "$PFW") + $(wattr w "$PFW")/2 - W/2 - X0))
Y=$(($(wattr y "$PFW") + $(wattr h "$PFW")/2 - H/2 - Y0))
# move mouse to optimal selection position
wmp -a $(($(wattr x "$PFW") + $(wattr w "$PFW") / 2 - W / 2 + 20)) \
$(($(wattr y "$PFW") + $(wattr h "$PFW") / 2 - H / 2 + 20))
fi
}
main() {
. fwmrc
wmenv
wmgaps
dcolours
PFM="$(pfm)"
FONT=$(awk '/font/ {print $3}' < ~/.Xresources | cut -d',' -f 1)
FH=15
W="150"
PROMPT=" Mosh >"
hosts="$(grep -w "host" ~/.ssh/config | cut -d\ -f 2)"
nHosts=$(printf '%s\n' "$hosts" | grep -cv "$PFW")
[ "$nHosts" -eq 0 ] && exit 1
case "$1" in
-m|menu) menu ;;
-c|center) center ;;
-h|--help|help) usage 0 ;;
esac
host=$(printf '%s\n' "$hosts" | \
dmenu -name "$(basename "$0")" -f -l "$nHosts" -fn "$FONT" -p "$PROMPT" \
-nf "#$NF" -sf "#$SF" -nb "#$NB" -sb "#$SB" -bc "#$BC" \
-s "$(mattr d "$PFM")" -x $X -y $Y -w "$W" -h "$FH" -bw $BW)
[ -n "$host" ] && urxvtc -g 85x22 -e sh -c "mosh $host || ssh $host"
}
main "$@"