Skip to content

Instantly share code, notes, and snippets.

@jasalt
Forked from bobthecow/tab.bash
Last active September 21, 2015 19:02
Show Gist options
  • Save jasalt/abcf2d53183399f85f29 to your computer and use it in GitHub Desktop.
Save jasalt/abcf2d53183399f85f29 to your computer and use it in GitHub Desktop.
Open new Terminal tabs from the command line
#!/bin/bash
#
# Open new Terminal tabs from the command line to currently running ITerm2
# session
#
# Author: Justin Hileman (http://justinhileman.com)
# Modified by: Jarkko Saltiola (http://saltio.la)
#
# Installation:
# Add this file path
#
# Usage:
# iterm Opens the current directory in a new tab
# iterm [PATH] Open PATH in a new tab
# iterm [CMD] Open a new tab and execute CMD
# iterm [PATH] [CMD] ... You can prob'ly guess
CMD=""
CDTO="$PWD"
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"
write text "clear"
end tell
end tell
end tell
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment