-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh
executable file
·87 lines (79 loc) · 2.2 KB
/
ssh
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
83
84
85
86
87
#!/bin/ksh
# Wrapper around the ssh binary to add the host name to the terminal window background
PATH="/opt/local/bin:$PATH"
if [ "$(tty)" == 'not a tty' ] || [ "$TERM_PROGRAM" != "iTerm.app" ]
then
exec /usr/bin/ssh "$@"
fi
function __calculate_iterm_window_dimensions {
typeset size=($(osascript -e "tell application \"iTerm\"
get bounds of window 1
end tell" | tr ',' ' '))
typeset x1=${size[0]} y1=${size[1]} x2=${size[2]} y2=${size[3]}
typeset w=$(( $x2 - $x1 - 15))
typeset h=$(( $y2 - $y1 - 44))
echo "${w}x${h}"
}
DIMENSIONS=$(__calculate_iterm_window_dimensions)
BG_COLOR="#222222"
#FG_COLOR="#662020"
#FG_COLOR="#9B0000"
FG_COLOR="#FFB507"
#FG_COLOR="#9D06E2"
GRAVITY="NorthEast"
OFFSET1="20,10"
OFFSET2="20,80"
FONT_SIZE="60"
FONT_STYLE="Normal"
#FONT="$HOME/.ksh/resources/SimpleLife.ttf"
#FONT="$HOME/Library/Fonts/Starjhol.TTF"
#FONT="$HOME/Library/Fonts/Starjout.TTF"
FONT="$HOME/Library/Fonts/Starjedi.ttf"
HOSTNAME=$(echo $@ | sed -e "s/.*@//" -e 's/-.* //' -e "s/ .*//" -e 's/\..*$//')
: ${SSH_HOSTNAME:=$HOSTNAME}
LOOKUP_TAB="${HOME}/.ssh/host-lookup"
if [ -f "$LOOKUP_TAB" ]
then
hst=$(grep "^${HOSTNAME}" "$LOOKUP_TAB")
if [ -n "$hst" ]
then
HOSTNAME=$(echo $hst | awk '{print $2}')
fi
fi
function set_bg {
typeset tty=$(tty)
osascript -e "
tell application \"iTerm\"
repeat with theTerminal in terminals
tell theTerminal
try
tell session id \"$tty\"
set background image path to \"$1\"
end tell
on error errmesg number errn
end try
end tell
end repeat
end tell"
}
on_exit () {
if [ ! -f /tmp/iTermBG.empty.png ]
then
convert \
-size "$DIMENSIONS" xc:"$BG_COLOR" -gravity "$GRAVITY" -fill "$FG_COLOR" \
-font "$FONT" -style "$FONT_STYLE" -pointsize "$FONT_SIZE" -antialias \
-draw "text $OFFSET1 '$(hostname -s)'" \
"/tmp/iTermBG.empty.png"
fi
set_bg
# set_bg "/tmp/iTermBG.empty.png"
rm "/tmp/iTermBG.$$.png"
}
trap on_exit EXIT
convert \
-size "$DIMENSIONS" xc:"$BG_COLOR" -gravity "$GRAVITY" -fill "$FG_COLOR" \
-font "$FONT" -style "$FONT_STYLE" -pointsize "$FONT_SIZE" -antialias \
-draw "text $OFFSET1 '${SSH_HOSTNAME}'" \
"/tmp/iTermBG.$$.png"
set_bg "/tmp/iTermBG.$$.png"
/usr/bin/ssh "$@"