-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruby-iTerm2.sh
executable file
·46 lines (36 loc) · 1.06 KB
/
ruby-iTerm2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
PATH_AND_FILE=$1
THE_PATH="${PATH_AND_FILE%/*}"
FILENAME="${PATH_AND_FILE##*/}"
echo "Script called"
echo "PATH_AND_FILE=$PATH_AND_FILE"
echo "THE_PATH=$THE_PATH"
echo "FILENAME=$FILENAME"
osascript <<EOF
tell application "iTerm"
activate
# Check to see if we have an open window. If not, open one.
if (count windows) is 0 then # no window is open.
create window with default profile
delay 0.5
end if
set currentWindow to current window # get a reference to current window
# We have an open window.
tell current session of currentWindow
if (is processing) or (name is not "bash") then # the current session is busy
tell currentWindow
create tab with default profile #- create a new tab
delay 0.5
end tell
end if
end tell
tell current session of currentWindow
# make sure we're in the right directory
write text "cd '$THE_PATH'"
delay 0.5
# run the script
set script_string to "$2" & " " & quoted form of "$FILENAME"
write text script_string
end tell
end tell
EOF