Last active
August 29, 2015 14:27
-
-
Save prufrock/b7ccc9dae164d728fc92 to your computer and use it in GitHub Desktop.
Rename this to ssh and put it some place where it will override ssh(but don't delete ssh) and you'll get robo backgrounds in your iterm. A modification of the ImageMagick script at http://kpumuk.info/mac-os-x/how-to-show-ssh-host-name-on-the-iterms-background/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# SSH with host name and IP address in background (only in iTerm.app) | |
# First, check to see if we have the correct terminal! | |
if [ "$(tty)" == 'not a tty' ] || [ "$TERM_PROGRAM" != "iTerm.app" ] ; then | |
/usr/bin/ssh "$@" | |
exit $? | |
fi | |
function __calculate_iterm_window_dimensions { | |
local size=( $(osascript -e "tell application \"iTerm\" | |
get bounds of window 1 | |
end tell" | tr ',' ' ') ) | |
local x1=${size[0]} y1=${size[1]} x2=${size[2]} y2=${size[3]} | |
# 15px - scrollbar width | |
local w=$(( $x2 - $x1 - 15 )) | |
# 44px - titlebar + tabs height | |
local h=$(( $y2 - $y1 - 44)) | |
echo "${w}x${h}" | |
} | |
# Console dimensions | |
DIMENSIONS=$(__calculate_iterm_window_dimensions) | |
BG_COLOR="#000000" # Background color | |
FG_COLOR="#662020" # Foreground color | |
GRAVITY="NorthEast" # Text gravity (NorthWest, North, NorthEast, | |
# West, Center, East, SouthWest, South, SouthEast) | |
OFFSET1="20,10" # Text offset (host name) | |
OFFSET2="20,80" # Text offset (ip address) | |
FONT_SIZE="60" # Font size in points | |
FONT_STYLE="Normal" # Font style (Any, Italic, Normal, Oblique) | |
# Font path | |
FONT="$HOME/.bash/resources/SimpleLife.ttf" | |
FAMILY="Georga" | |
HOSTNAME=`echo $@ | sed -e "s/.*@//" -e "s/ .*//"` | |
output=`dscacheutil -q host -a name $HOSTNAME` | |
RESOLVED_HOSTNAME=`echo -e "$output"|grep '^name:'|awk '{print $2}'` | |
RESOLVED_IP=`echo -e "$output"|grep '^ip_address:'|awk '{print $2}'` | |
function set_bg { | |
local 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" "/tmp/iTermBG.empty.png" | |
fi | |
set_bg "/tmp/iTermBG.empty.png" | |
# rm "/tmp/iTermBG.$$.png" | |
} | |
trap on_exit EXIT | |
ARGS_HASH=$(echo -n "$@" | md5) | |
ITERM_BG=$HOME/.iTerm/$ARGS_HASH.png | |
if [ ! -f $ITERM_BG ]; then | |
curl https://robohash.org/$ARGS_HASH.png \ | |
-o $ITERM_BG | |
fi | |
set_bg $ITERM_BG | |
/usr/bin/ssh "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment