Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Aaron Fendley committed Aug 16, 2011
0 parents commit be92d27
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
8 changes: 8 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
echo "Downloading..."
/usr/bin/env git clone https://github.com/tricon/set-bg.git /tmp/set-bg

echo "Installing..."
sudo cp /tmp/set-bg/* /usr/bin/
echo "alias ssh=sshb" >> ~/.zshrc

echo "Done!"
17 changes: 17 additions & 0 deletions set-bg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

current_tty=$(tty)
osascript -e "
tell application \"iTerm\"
repeat with theTerminal in terminals
tell theTerminal
try
tell session id \"$current_tty\"
set background image path to \"$1\"
end tell
on error errmesg number errn
end try
end tell
end repeat
end tell
"
44 changes: 44 additions & 0 deletions set-bg-host
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/zsh

function __calculate_iterm_window_dimensions {
applescript="tell application \"iTerm\"
get bounds of window 1
end tell"
size=($(osascript -e $applescript | tr ',' ' '))

x1=${size[1]} y1=${size[2]} x2=${size[3]} y2=${size[4]}
# 15px - scrollbar width
w=$(( $x2 - $x1 ))
# 44px - titlebar + tabs height
h=$(( $y2 - $y1 - 44))
echo "${w}x${h}"
}

# Console dimensions
DIMENSIONS=$(__calculate_iterm_window_dimensions)
a=(${(s/x/)DIMENSIONS})
WIDTH=$(($a[1]-32))
HEIGHT=$(($a[2]-32))

BG_COLOR="#121212" # Background color
FG_COLOR="#454545" # Foreground color
GRAVITY="SouthEast" # Text gravity (NorthWest, North, NorthEast,
FONT_SIZE="20" # Font size in points
FONT="Helvetica-Light"

OFFSET_X=35
OFFSET_Y=04

HOSTNAME=$(/usr/bin/base-hostname "$@")
DESTFILE="/tmp/iTermBG.$HOSTNAME.png"

# if [ ! -f /tmp/iTermBG.${HOSTNAME}.png ]; then
convert -crop ${DIMENSIONS}-$WIDTH-$HEIGHT\! ~/Pictures/GeekTool/Apple.png \
-background "$BG_COLOR" -flatten -quality 100 -gravity "$GRAVITY" -font "$FONT" -pointsize "$FONT_SIZE" -antialias -alpha Off \
-fill black -annotate +$(($OFFSET_X+1))+$(($OFFSET_Y+1)) "$HOSTNAME" \
-fill "#323232" -annotate +$(($OFFSET_X-1))+$(($OFFSET_Y-1)) "$HOSTNAME" \
-fill "#252525" -annotate +$OFFSET_X+$OFFSET_Y "$HOSTNAME" \
$DESTFILE
# fi

/usr/bin/set-bg $DESTFILE
25 changes: 25 additions & 0 deletions sshb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# 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

HOSTNAME=$(/usr/bin/base-hostname `hostname`)

on_exit () {
# if [ ! -f /tmp/iTermBG.empty.png ]; then
# convert -size "$DIMENSIONS" xc:"$BG_COLOR" "/tmp/iTermBG.empty.png"
# fi
/usr/bin/set-bg "/tmp/iTermBG.$HOSTNAME.png"
}

trap on_exit EXIT

/usr/bin/set-bg-host "$@"

# read $tmp
/usr/bin/ssh "$@"

0 comments on commit be92d27

Please sign in to comment.