Created
January 22, 2020 04:31
-
-
Save brightzheng100/65d33790594e63b336d0d65e234062f0 to your computer and use it in GitHub Desktop.
iTerm Tips
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 | |
# 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