Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Oh My Zsh
Commits
689b5ab3
Commit
689b5ab3
authored
Jun 26, 2015
by
Andrew Janke
Browse files
osx: fix tab* functions so cd works in iTerm2, exit status is correct, and
error messages are not discarded.
parent
599831b8
Changes
1
Show whitespace changes
Inline
Side-by-side
plugins/osx/osx.plugin.zsh
View file @
689b5ab3
...
@@ -5,29 +5,35 @@
...
@@ -5,29 +5,35 @@
# VERSION: 1.1.0
# VERSION: 1.1.0
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
function
tab
()
{
function
_omz_osx_get_frontmost_app
()
{
local command
=
"cd
\\\"
$PWD
\\\"
; clear; "
local
the_app
=
$(
((
$#
>
0
))
&&
command
=
"
${
command
}
;
$*
"
the_app
=
$(
osascript 2>/dev/null
<<
EOF
osascript 2>/dev/null
<<
EOF
tell application "System Events"
tell application "System Events"
name of first item of (every process whose frontmost is true)
name of first item of (every process whose frontmost is true)
end tell
end tell
EOF
EOF
)
)
echo
"
$the_app
"
}
[[
"
$the_app
"
==
'Terminal'
]]
&&
{
function
tab
()
{
osascript 2>/dev/null
<<
EOF
# Must not have trailing semicolon, for iTerm compatibility
local command
=
"cd
\\\"
$PWD
\\\"
; clear"
((
$#
>
0
))
&&
command
=
"
${
command
}
;
$*
"
local
the_app
=
$(
_omz_osx_get_frontmost_app
)
if
[[
"
$the_app
"
==
'Terminal'
]]
;
then
# Discarding stdout to quash "tab N of window id XXX" output
osascript
>
/dev/null
<<
EOF
tell application "System Events"
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
tell process "Terminal" to keystroke "t" using command down
tell application "Terminal" to do script "
${
command
}
" in front window
end tell
end tell
tell application "Terminal" to do script "
${
command
}
" in front window
EOF
EOF
}
[[
"
$the_app
"
==
'iTerm'
]]
&&
{
elif
[[
"
$the_app
"
==
'iTerm'
]]
;
then
osascript
2>/dev/null
<<
EOF
osascript
<<
EOF
tell application "iTerm"
tell application "iTerm"
set current_terminal to current terminal
set current_terminal to current terminal
tell current_terminal
tell current_terminal
...
@@ -35,29 +41,27 @@ EOF
...
@@ -35,29 +41,27 @@ EOF
set current_session to current session
set current_session to current session
tell current_session
tell current_session
write text "
${
command
}
"
write text "
${
command
}
"
keystroke return
end tell
end tell
end tell
end tell
end tell
end tell
EOF
EOF
}
else
echo
"tab: unsupported terminal app:
$the_app
"
false
fi
}
}
function
vsplit_tab
()
{
function
vsplit_tab
()
{
local command
=
"cd
\\\"
$PWD
\\\"
"
local command
=
"cd
\\\"
$PWD
\\\"
; clear
"
((
$#
>
0
))
&&
command
=
"
${
command
}
;
$*
"
((
$#
>
0
))
&&
command
=
"
${
command
}
;
$*
"
the_app
=
$(
local
the_app
=
$(
_omz_osx_get_frontmost_app
)
osascript 2>/dev/null
<<
EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
[[
"
$the_app
"
==
'iTerm'
]]
&&
{
if
[[
"
$the_app
"
==
'iTerm'
]]
;
then
osascript
2>/dev/null
<<
EOF
osascript
<<
EOF
tell application "iTerm" to activate
--
tell application "iTerm" to activate
tell application "System Events"
tell application "System Events"
tell process "iTerm"
tell process "iTerm"
...
@@ -65,26 +69,24 @@ EOF
...
@@ -65,26 +69,24 @@ EOF
click
click
end tell
end tell
end tell
end tell
keystroke "
${
command
}
; clear;"
keystroke "
${
command
}
\n
"
keystroke return
end tell
end tell
EOF
EOF
}
else
echo
"
$0
: unsupported terminal app:
$the_app
"
>
&2
false
fi
}
}
function
split_tab
()
{
function
split_tab
()
{
local command
=
"cd
\\\"
$PWD
\\\"
"
local command
=
"cd
\\\"
$PWD
\\\"
; clear
"
((
$#
>
0
))
&&
command
=
"
${
command
}
;
$*
"
((
$#
>
0
))
&&
command
=
"
${
command
}
;
$*
"
the_app
=
$(
local
the_app
=
$(
_omz_osx_get_frontmost_app
)
osascript 2>/dev/null
<<
EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
[[
"
$the_app
"
==
'iTerm'
]]
&&
{
if
[[
"
$the_app
"
==
'iTerm'
]]
;
then
osascript 2>/dev/null
<<
EOF
osascript 2>/dev/null
<<
EOF
tell application "iTerm" to activate
tell application "iTerm" to activate
...
@@ -94,11 +96,15 @@ EOF
...
@@ -94,11 +96,15 @@ EOF
click
click
end tell
end tell
end tell
end tell
keystroke "
${
command
}
; clear;"
keystroke "
${
command
}
\n
"
keystroke return
end tell
end tell
EOF
EOF
}
else
echo
"
$0
: unsupported terminal app:
$the_app
"
>
&2
false
fi
}
}
function
pfd
()
{
function
pfd
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment