Last active
August 29, 2015 13:56
-
-
Save btisdall/8972305 to your computer and use it in GitHub Desktop.
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 | |
# | |
# Runs the 'Duplicate iTerm tab' AppleScript, enabling iTerm 2 to run this AppleScript when a | |
# given keyboard shortcut is triggered. | |
get_tty_cwd(){ | |
TTY=$1 | |
PID=`ps -f | grep $TTY | head -n 1 | awk '{ print $2; }'` | |
lsof -a -d cwd -F n -p $PID | egrep -v 'p[0-9]+' | awk '{ sub(/^n/, ""); print; }' | |
} | |
export -f get_tty_cwd | |
osascript <<EOF | |
-- Duplicate iTerm tab.scpt | |
tell application "iTerm" | |
tell the current terminal | |
tell the current session | |
set the_name to get name | |
set tty_name to do shell script "basename " & (get tty) | |
set working_dir to do shell script "get_tty_cwd " & tty_name | |
end tell | |
launch session "Default Session" | |
tell the last session | |
set name to the_name | |
write text "cd '" & working_dir & "'" | |
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