From 689b5ab3c8c8bf30ee63cafb8401d7d95e41f359 Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Fri, 26 Jun 2015 01:48:17 -0400 Subject: osx: fix tab* functions so cd works in iTerm2, exit status is correct, and error messages are not discarded. --- plugins/osx/osx.plugin.zsh | 84 +++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 39 deletions(-) (limited to 'plugins/osx') 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 </dev/null < 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 </dev/null < 0 )) && command="${command}; $*" - the_app=$( - osascript 2>/dev/null </dev/null <&2 + false + + fi } function split_tab() { - local command="cd \\\"$PWD\\\"" + local command="cd \\\"$PWD\\\"; clear" (( $# > 0 )) && command="${command}; $*" - the_app=$( - osascript 2>/dev/null </dev/null <&2 + false + + fi } function pfd() { -- cgit v1.2.3-70-g09d2 From 0a2c31fb60ab9870f3a2090eba10d0bdbcc9a3b9 Mon Sep 17 00:00:00 2001 From: MoonFruit Date: Fri, 28 Aug 2015 10:46:45 +0800 Subject: Remove redundant semicolon Remove redundant semicolon to make tab() works better in ITerm 2. --- plugins/osx/osx.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/osx') diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index a6e3a83e6..390960fdc 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -6,7 +6,7 @@ # ------------------------------------------------------------------------------ function tab() { - local command="cd \\\"$PWD\\\"; clear; " + local command="cd \\\"$PWD\\\"; clear" (( $# > 0 )) && command="${command}; $*" the_app=$( -- cgit v1.2.3-70-g09d2 From a746e6010ae2b260213f081789eaff01865f5664 Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Mon, 14 Sep 2015 19:27:41 +1200 Subject: Update osx.plugin.zsh Added function to display the song you're currently listening to in iTunes Fixed indent Indentation on line 169 was squiffy Fixed spelling Removed unnecessary wording to make function more succinct. Highlighting of Artist and Track Changed the highlighting of the Track and Artist in yellow to make use of Prompt Expansion Colors --- plugins/osx/osx.plugin.zsh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'plugins/osx') diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 390960fdc..044276c1c 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -161,6 +161,15 @@ function itunes() { vol) opt="set sound volume to $1" #$1 Due to the shift ;; + playing) + local state=`osascript -e 'tell application "iTunes" to player state as string'` + if [ "$state" = "playing" ]; then + currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` + currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` + echo "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; + fi + return 0 + ;; shuf|shuff|shuffle) # The shuffle property of current playlist can't be changed in iTunes 12, # so this workaround uses AppleScript to simulate user input instead. @@ -199,6 +208,7 @@ EOF echo "\tnext|previous\tplay next or previous track" echo "\tshuf|shuffle [on|off|toggle]\tSet shuffled playback. Default: toggle. Note: toggle doesn't support the MiniPlayer." echo "\tvol\tSet the volume, takes an argument from 0 to 100" + echo "\tplaying\tShow what song is currently playing in iTunes." echo "\thelp\tshow this message and exit" return 0 ;; -- cgit v1.2.3-70-g09d2 From 29db0e0119aba4f317ac320ed5089b82142bcb10 Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Thu, 17 Sep 2015 13:48:30 +1200 Subject: Fixed colourisation of Now Playing function --- plugins/osx/osx.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/osx') diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 044276c1c..f1b437189 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -166,7 +166,7 @@ function itunes() { if [ "$state" = "playing" ]; then currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` - echo "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; + print -P "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; fi return 0 ;; -- cgit v1.2.3-70-g09d2 From 9f2acdc445f05e6556cf6180a1edd52b6939bbcc Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Thu, 17 Sep 2015 18:28:48 +1200 Subject: You can now use 'itunes status' as well as 'itunes playing' to show current track --- plugins/osx/osx.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/osx') diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index f1b437189..859e08da5 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -161,9 +161,9 @@ function itunes() { vol) opt="set sound volume to $1" #$1 Due to the shift ;; - playing) + playing|status) local state=`osascript -e 'tell application "iTunes" to player state as string'` - if [ "$state" = "playing" ]; then + if [[ "$state" = "playing" ]]; then currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` print -P "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; -- cgit v1.2.3-70-g09d2 From 993e09cc6b6127be92afe072f5957e4e9e72367f Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Thu, 17 Sep 2015 19:12:35 +1200 Subject: Added function for 'itunes playing' to display state when not playing --- plugins/osx/osx.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'plugins/osx') diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 859e08da5..9413f5056 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -167,6 +167,8 @@ function itunes() { currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` print -P "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; + else + print "iTunes is" $state; fi return 0 ;; @@ -208,7 +210,7 @@ EOF echo "\tnext|previous\tplay next or previous track" echo "\tshuf|shuffle [on|off|toggle]\tSet shuffled playback. Default: toggle. Note: toggle doesn't support the MiniPlayer." echo "\tvol\tSet the volume, takes an argument from 0 to 100" - echo "\tplaying\tShow what song is currently playing in iTunes." + echo "\tplaying|status\tShow what song is currently playing in iTunes." echo "\thelp\tshow this message and exit" return 0 ;; -- cgit v1.2.3-70-g09d2 From 326c2b08593e9b02da149dcc0d3c5cf99b21d3a2 Mon Sep 17 00:00:00 2001 From: Andy Bateman Date: Sun, 20 Sep 2015 08:46:45 +1200 Subject: Replaced the use of 'print' with 'echo' in order to sanitise track and artist names Fixed indentation Fixed indentation --- plugins/osx/osx.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/osx') diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index 9413f5056..86778363b 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -166,9 +166,9 @@ function itunes() { if [[ "$state" = "playing" ]]; then currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` - print -P "Listening to %F{yellow}$currenttrack%f by %F{yellow}$currentartist%f"; + echo -E "Listening to $fg[yellow]$currenttrack$reset_color by $fg[yellow]$currentartist$reset_color"; else - print "iTunes is" $state; + echo "iTunes is" $state; fi return 0 ;; -- cgit v1.2.3-70-g09d2