Skip to content

Instantly share code, notes, and snippets.

@brightzheng100
Created January 22, 2020 04:31
Show Gist options
  • Save brightzheng100/65d33790594e63b336d0d65e234062f0 to your computer and use it in GitHub Desktop.
Save brightzheng100/65d33790594e63b336d0d65e234062f0 to your computer and use it in GitHub Desktop.
iTerm Tips
#!/bin/bash
# Ref: https://gist.github.com/bobthecow/757788
# Purposes: to open a new iTerm tab vertically, with the same profile, and run the command.
# Usage: source it and
# 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
# Example:
# tab echo 123
[ `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 "iTerm"
activate
tell current session of current window to set newTab to split vertically with same profile
tell newTab
select
write text "cd \"$cdto\"$cmd"
end tell
end tell
EOF
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment