forked from wbond/sublime_terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iTerm.sh
executable file
·73 lines (69 loc) · 1.29 KB
/
iTerm.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/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 terminal
launch session "Default Session"
tell the last session
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 terminals) = 0 then
set term to (make new terminal)
else
set term to current terminal
end if
tell term
launch session "Default Session"
tell the last session
write text "$CD_CMD"
end tell
end tell
end tell
EOF
else
osascript &>/dev/null <<EOF
tell application "iTerm"
set term to (make new terminal)
tell term
launch session "Default Session"
tell the last session
write text "$CD_CMD"
end tell
end tell
end tell
EOF
fi
fi