Skip to content

Instantly share code, notes, and snippets.

@simonc
Created October 14, 2009 19:35
Show Gist options
  • Save simonc/210344 to your computer and use it in GitHub Desktop.
Save simonc/210344 to your computer and use it in GitHub Desktop.
Sets the remote hostname as iTerm background
#!/usr/bin/env bash
BG_COLOR="#000000" # Background color
FG_COLOR="#662020" # Foreground color
DIMENSIONS="570x342" # Console dimensions
GRAVITY="NorthEast" # Text gravity (NorthWest, North, NorthEast,
# West, Center, East, SouthWest, South, SouthEast)
OFFSET="20,10" # Text offset
FONT_SIZE="60" # Font size in points
FONT_FAMILY="Monaco" # Font family
FONT_STYLE="Normal" # Font style (Any, Italic, Normal, Oblique)
HOSTNAME=`echo $@ | sed "s/.*@//" | sed "s/ .*//"`
set_bg () {
osascript -e "tell application \"iTerm\"
set current_terminal to (current terminal)
tell current_terminal
set current_session to (current session)
tell current_session
set background image path to \"$1\"
end tell
end tell
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
convert -size "$DIMENSIONS" xc:"$BG_COLOR" -gravity "$GRAVITY" -fill "$FG_COLOR" -family "$FONT_FAMILY" -style "$FONT_STYLE" -pointsize "$FONT_SIZE" -antialias -draw "text $OFFSET '$HOSTNAME'" "/tmp/iTermBG.$$.png"
set_bg "/tmp/iTermBG.$$.png"
`which ssh` "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment