Skip to content

Instantly share code, notes, and snippets.

@mobmad
Created September 21, 2010 09:31
Show Gist options
  • Save mobmad/589455 to your computer and use it in GitHub Desktop.
Save mobmad/589455 to your computer and use it in GitHub Desktop.
open a new terminal tab with the same path and (optionally) pass params to the new tab
# Inspired from http://elsethenif.wordpress.com/2009/06/11/open-a-new-tab-on-terminal-with-the-same-path-on-mac-os-x/
# Put this in your ~/.bash_profile
# Added functinality to pass commands to the new tab
# Examples:
# Open a new tab in terminal with the same path:
# nt
# Open a new tab with the same path, and pass command "script/server":
# nt script/server
# Open a new tab with the same path, list all files and navigate one directory up:
# nt ls "cd .."
function nt {
COMMANDS="
tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down
tell application \"Terminal\" to do script \"cd $PWD \" in selected tab of the front window
tell application \"Terminal\" to do script \"clear\" in selected tab of the front window
"
for p in "$@"
do
append="tell application \"Terminal\" to do script \"$p\" in selected tab of the front window
"
COMMANDS="$COMMANDS$append"
done
osascript -e "$COMMANDS" > /dev/null 2>&1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment