dde5540b1e44fabfa25a183975b5edaa80dd3355
- Author
- Robby Russell <robby@planetargon.com>
- Committer
- Robby Russell <robby@planetargon.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
2index 390960fdcc162c6701fe0c066772f32d75460bb8..2cbb95977af17c2bc88a731b8e1e711e2139c860 100644
3--- a/plugins/osx/osx.plugin.zsh
4+++ b/plugins/osx/osx.plugin.zsh
5@@ -5,29 +5,35 @@
6 # VERSION: 1.1.0
7 # ------------------------------------------------------------------------------
8
9-function tab() {
10- local command="cd \\\"$PWD\\\"; clear"
11- (( $# > 0 )) && command="${command}; $*"
12-
13- the_app=$(
14+function _omz_osx_get_frontmost_app() {
15+ local the_app=$(
16 osascript 2>/dev/null <<EOF
17 tell application "System Events"
18 name of first item of (every process whose frontmost is true)
19 end tell
20 EOF
21 )
22+ echo "$the_app"
23+}
24
25- [[ "$the_app" == 'Terminal' ]] && {
26- osascript 2>/dev/null <<EOF
27+function tab() {
28+ # Must not have trailing semicolon, for iTerm compatibility
29+ local command="cd \\\"$PWD\\\"; clear"
30+ (( $# > 0 )) && command="${command}; $*"
31+
32+ local the_app=$(_omz_osx_get_frontmost_app)
33+
34+ if [[ "$the_app" == 'Terminal' ]]; then
35+ # Discarding stdout to quash "tab N of window id XXX" output
36+ osascript >/dev/null <<EOF
37 tell application "System Events"
38 tell process "Terminal" to keystroke "t" using command down
39- tell application "Terminal" to do script "${command}" in front window
40 end tell
41+ tell application "Terminal" to do script "${command}" in front window
42 EOF
43- }
44
45- [[ "$the_app" == 'iTerm' ]] && {
46- osascript 2>/dev/null <<EOF
47+ elif [[ "$the_app" == 'iTerm' ]]; then
48+ osascript <<EOF
49 tell application "iTerm"
50 set current_terminal to current terminal
51 tell current_terminal
52@@ -35,29 +41,27 @@ EOF
53 set current_session to current session
54 tell current_session
55 write text "${command}"
56- keystroke return
57 end tell
58 end tell
59 end tell
60 EOF
61- }
62+
63+ else
64+ echo "tab: unsupported terminal app: $the_app"
65+ false
66+
67+ fi
68 }
69
70 function vsplit_tab() {
71- local command="cd \\\"$PWD\\\""
72+ local command="cd \\\"$PWD\\\"; clear"
73 (( $# > 0 )) && command="${command}; $*"
74
75- the_app=$(
76- osascript 2>/dev/null <<EOF
77- tell application "System Events"
78- name of first item of (every process whose frontmost is true)
79- end tell
80-EOF
81- )
82+ local the_app=$(_omz_osx_get_frontmost_app)
83
84- [[ "$the_app" == 'iTerm' ]] && {
85- osascript 2>/dev/null <<EOF
86- tell application "iTerm" to activate
87+ if [[ "$the_app" == 'iTerm' ]]; then
88+ osascript <<EOF
89+ -- tell application "iTerm" to activate
90
91 tell application "System Events"
92 tell process "iTerm"
93@@ -65,26 +69,24 @@ EOF
94 click
95 end tell
96 end tell
97- keystroke "${command}; clear;"
98- keystroke return
99+ keystroke "${command} \n"
100 end tell
101 EOF
102- }
103+
104+ else