Skip to content

Instantly share code, notes, and snippets.

@virajkulkarni14
Created March 6, 2018 16:47
Show Gist options
  • Select an option

  • Save virajkulkarni14/d187c30fc5bed2d9044b92c277304a00 to your computer and use it in GitHub Desktop.

Select an option

Save virajkulkarni14/d187c30fc5bed2d9044b92c277304a00 to your computer and use it in GitHub Desktop.
Open new Terminal panes from the command line: will open horizontal tab; cursors will remain in originating pane (modification from https://gist.github.com/bobthecow/757788)
#!/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 teh Mac users
[ `uname -s` != "Darwin" ] && return
function tab () {
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 "iTerm2"
tell current session of current window
set newPane to (split horizontally with default profile)
tell newPane
write text "cd \"$cdto\"$cmd"
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