summaryrefslogtreecommitdiff
path: root/plugins/osx
diff options
context:
space:
mode:
authorChris McCuller <cmcculler@salesforce.com>2015-09-21 22:19:15 -0400
committerChris McCuller <cmcculler@salesforce.com>2015-09-21 22:19:15 -0400
commite6ccd37b0563b4e7b34c41034766b9789e43ee5c (patch)
treec12c8c2c6437fd7d5d3ec5bff27634a80759b808 /plugins/osx
parent30ef85664822595e29acdbc840c45d5772d84b5d (diff)
parent76a26a2a59d8c6d0f65a4426cdb93920e255aea7 (diff)
downloadzsh-e6ccd37b0563b4e7b34c41034766b9789e43ee5c.tar.gz
zsh-e6ccd37b0563b4e7b34c41034766b9789e43ee5c.tar.bz2
zsh-e6ccd37b0563b4e7b34c41034766b9789e43ee5c.zip
Merge master (rebase being super annoying). Fix conflicts
Diffstat (limited to 'plugins/osx')
-rw-r--r--plugins/osx/osx.plugin.zsh84
1 files changed, 45 insertions, 39 deletions
diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
index a6e3a83e6..2cbb95977 100644
--- a/plugins/osx/osx.plugin.zsh
+++ b/plugins/osx/osx.plugin.zsh
@@ -5,29 +5,35 @@
# VERSION: 1.1.0
# ------------------------------------------------------------------------------
-function tab() {
- local command="cd \\\"$PWD\\\"; clear; "
- (( $# > 0 )) && command="${command}; $*"
-
- the_app=$(
+function _omz_osx_get_frontmost_app() {
+ local the_app=$(
osascript 2>/dev/null <<EOF
tell application "System Events"
name of first item of (every process whose frontmost is true)
end tell
EOF
)
+ echo "$the_app"
+}
- [[ "$the_app" == 'Terminal' ]] && {
- osascript 2>/dev/null <<EOF
+function tab() {
+ # 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 process "Terminal" to keystroke "t" using command down
- tell application "Terminal" to do script "${command}" in front window
end tell
+ tell application "Terminal" to do script "${command}" in front window
EOF
- }
- [[ "$the_app" == 'iTerm' ]] && {
- osascript 2>/dev/null <<EOF
+ elif [[ "$the_app" == 'iTerm' ]]; then
+ osascript <<EOF
tell application "iTerm"
set current_terminal to current terminal
tell current_terminal
@@ -35,29 +41,27 @@ EOF
set current_session to current session
tell current_session
write text "${command}"
- keystroke return
end tell
end tell
end tell
EOF
- }
+
+ else
+ echo "tab: unsupported terminal app: $the_app"
+ false
+
+ fi
}
function vsplit_tab() {
- local command="cd \\\"$PWD\\\""
+ local command="cd \\\"$PWD\\\"; clear"
(( $# > 0 )) && command="${command}; $*"
- the_app=$(
- osascript 2>/dev/null <<EOF
- tell application "System Events"
- name of first item of (every process whose frontmost is true)
- end tell
-EOF
- )
+ local the_app=$(_omz_osx_get_frontmost_app)
- [[ "$the_app" == 'iTerm' ]] && {
- osascript 2>/dev/null <<EOF
- tell application "iTerm" to activate
+ if [[ "$the_app" == 'iTerm' ]]; then
+ osascript <<EOF
+ -- tell application "iTerm" to activate
tell application "System Events"
tell process "iTerm"
@@ -65,26 +69,24 @@ EOF
click
end tell
end tell
- keystroke "${command}; clear;"
- keystroke return
+ keystroke "${command} \n"
end tell
EOF
- }
+
+ else
+ echo "$0: unsupported terminal app: $the_app" >&2
+ false
+
+ fi
}
function split_tab() {
- local command="cd \\\"$PWD\\\""
+ local command="cd \\\"$PWD\\\"; clear"
(( $# > 0 )) && command="${command}; $*"
- the_app=$(
- osascript 2>/dev/null <<EOF
- tell application "System Events"
- name of first item of (every process whose frontmost is true)
- end tell
-EOF
- )
+ local the_app=$(_omz_osx_get_frontmost_app)
- [[ "$the_app" == 'iTerm' ]] && {
+ if [[ "$the_app" == 'iTerm' ]]; then
osascript 2>/dev/null <<EOF
tell application "iTerm" to activate
@@ -94,11 +96,15 @@ EOF
click
end tell
end tell
- keystroke "${command}; clear;"
- keystroke return
+ keystroke "${command} \n"
end tell
EOF
- }
+
+ else
+ echo "$0: unsupported terminal app: $the_app" >&2
+ false
+
+ fi
}
function pfd() {