-
-
Save figpope/77ba3d887daf6ad56979afb283f17788 to your computer and use it in GitHub Desktop.
Open new Terminal tabs from the command line
This file contains 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 | |
# | |
# Open new Terminal tabs from the command line | |
# | |
# Author: Justin Hileman (http://justinhileman.com) | |
# | |
# Installation: | |
# Add the following function to your `.bashrc` or `.bash_profile`, | |
# or save it somewhere (e.g. `~/.tab.bash`) and source it in `.bashrc` | |
# | |
# Usage: | |
# tab Opens the current directory in a new tab | |
# tab [PATH] Open PATH in a new tab | |
# tab [CMD] Open a new tab and execute CMD | |
# tab [PATH] [CMD] ... You can prob'ly guess | |
# Only for Mac users | |
[ `uname -s` != "Darwin" ] && exit 1 | |
cdto="$PWD" | |
cmd="" | |
args="$@" | |
if [ -d "$1" ]; then | |
cdto=`cd "$1"; pwd` | |
args="${@:2}" | |
fi | |
if [ -n "$args" ]; then | |
cmd="; $args" | |
fi | |
osascript - "$@" <<EOF | |
on run argv | |
tell application "iTerm" | |
activate | |
set new_term to (create window with default profile) | |
tell new_term | |
tell the current session | |
repeat with arg in argv | |
write text "cd \"$cdto\"$cmd" | |
end repeat | |
end tell | |
end tell | |
end tell | |
end run | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment