Skip to content

Instantly share code, notes, and snippets.

@gnachman
Created July 30, 2015 02:56
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gnachman/b9ae9cf06c44b5a95edf to your computer and use it in GitHub Desktop.
#!/bin/bash
CD_CMD="cd "\\\"$(pwd)\\\"" && clear"
if echo "$SHELL" | grep -E "/fish$" &> /dev/null; then
CD_CMD="cd "\\\"$(pwd)\\\""; and clear"
fi
VERSION=$(sw_vers -productVersion)
OPEN_IN_TAB=0
while [ "$1" != "" ]; do
PARAM="$1"
VALUE="$2"
case "$PARAM" in
--open-in-tab)
OPEN_IN_TAB=1
;;
esac
shift
done
if (( $(expr $VERSION '<' 10.7) )); then
RUNNING=$(osascript<<END
tell application "System Events"
count(processes whose name is "iTerm")
end tell
END
)
else
RUNNING=1
fi
if (( ! $RUNNING )); then
osascript<<END
tell application "iTerm"
tell current window
tell current session of (create tab with default profile)
write text "$CD_CMD"
end tell
end tell
end tell
END
else
if (( $OPEN_IN_TAB )); then
osascript &>/dev/null <<EOF
tell application "iTerm"
if (count of windows) = 0 then
set theWindow to (create window with default profile)
set theSession to current session of theWindow
else
set theWindow to current window
tell current window
set theTab to create tab with default profile
set theSession to current session of theTab
end tell
end if
tell theSession
write text "$CD_CMD"
end tell
end tell
EOF
else
osascript &>/dev/null <<EOF
tell application "iTerm"
tell (create window with default profile)
tell the current session
write text "$CD_CMD"
end tell
end tell
end tell
EOF
fi
fi
@ushuz
Copy link

ushuz commented Jul 26, 2016

Have to replace "iTerm" with "iTerm2" to make it work with latest iTerm2 3.0.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment