Skip to content

Instantly share code, notes, and snippets.

@urre
Last active August 29, 2015 14:06
Show Gist options
  • Save urre/4b740160f2fd99ad286a to your computer and use it in GitHub Desktop.
Save urre/4b740160f2fd99ad286a to your computer and use it in GitHub Desktop.
Simple example dev setup which opens separate tabs in iTerm for different tasks/runners/servers
#!/bin/bash
# **************************************************************************************
#
# Devtabs
#
# Simple example dev setup which opens separate tabs in iTerm for different tasks/runners/servers
# @urre 140715
#
# **************************************************************************************
# Usage:
# bash devtabs.sh
# Usage with Alfred (Powerpack required)
# 1. Open up Alfred
# 2. Preferences -> Workflows
# 3. Add input keyword and then Add (+) -> Actions
# 4. Choose Run script
# 5. Choose Bash and add this script
# 6. Connect keyword and action -> Save
# Commands usage:
# newtab Opens the current directory in a new new tab
# newtab [PATH] Open PATH in a new tab
# newtab [CMD] Open a new tab and execute CMD
# newtab [PATH] [CMD] ... Yup :)
function newtab () {
local cmd=""
local cdto="$PWD"
local args="$@"
if [ -d "$1" ]; then
cdto=`cd "$1"; pwd`
args="${@:2}"
fi
if [ -n "$args" ]; then
cmd="; $args"
fi
osascript &>/dev/null <<EOF
tell application "iTerm"
tell current terminal
launch session "Default Session"
tell the last session
write text "cd \"$cdto\"$cmd"
end tell
end tell
end tell
EOF
}
# Just some examples, add/edit/remove below:
# Start Memcached
newtab /path/to/sites/site ./startmemcached.sh
# Start MongoDB
newtab /path/to/sites/site ./startmongo.sh
# Concat and minify Javscript with Grunt
newtab /path/to/sites/site/static grunt watch:all
# Compile CSS with Compass
newtab /path/to/sites/site/static/styles compass watch
# Open in default browser
newtab open 'http://site.loc'
# Open project in Sublime Text
newtab /path/to/sites/site 'subl . && sleep 0.1 && subl .'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment