Created
August 2, 2013 06:45
-
-
Save mmenozzi/6137938 to your computer and use it in GitHub Desktop.
Script that resizes and crop an image and then sets as background for iTerm
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 | |
# Script that resizes and crop an image and then sets as background for iTerm | |
# First, check to see if we have the correct terminal! | |
if [ "$(tty)" == 'not a tty' ] || [ "$TERM_PROGRAM" != "iTerm.app" ] ; then | |
exit $? | |
fi | |
# Console dimensions | |
# Generate dimension based on screensize | |
H=$((1440/178*`stty size | cut -d ' ' -f2`)) | |
V=$((900/47*`stty size | cut -d ' ' -f1`)) | |
DIMENSIONS=$H"x"$V | |
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" | |
} | |
convert /path/to/source-image.jpg -resize "$DIMENSIONS^" -gravity center -crop $DIMENSIONS+0+0 +repage /tmp/iterm-bg-$DIMENSIONS.jpg | |
set_bg "/tmp/iterm-bg-$DIMENSIONS.jpg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment