ff5629e60b815b3c21ef216d5ba5943932589758

Author
Ryan Brushett <RyanBrushett@users.noreply.github.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Improve UX for Spotify quit command in osx plugin (#5726)

* Improve UX for Spotify commands in osx plugin

Spotify command UX is a bit weak for people who live and work almost entirely in shells.
- `spotify quit` should not open Spotify if it is not already running. Should confirm that Spotify is indeed not running.
- `spotify quit` should not blow away the user's shell once Spotify is quit. This can be a disruption to work flow.

This PR looks to add a few little checks which will help improve this experience.
This PR also adds a space to line 477 between `break` and `;;` for consistency. Doesn't seem like a big enough change to put in its own PR.

* Rearranging output as per peer feedback

* osx plugin's spotify: change quitting w/ closing

Closing is more idiomatic English.

Diff

 1diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
 2index d7baa11910b272eb62809a9c2928897872a2dd43..95ef3e1aa75d0ee7109cd0b8a006da0913710c9f 100644
 3--- a/plugins/osx/osx.plugin.zsh
 4+++ b/plugins/osx/osx.plugin.zsh
 5@@ -323,7 +323,7 @@ function spotify() {
 6   if [ $# = 0 ]; then
 7     showHelp;
 8   else
 9-    if [ "$(osascript -e 'application "Spotify" is running')" = "false" ]; then
10+    if [ "$1" != "quit" ] && [ "$(osascript -e 'application "Spotify" is running')" = "false" ]; then
11       osascript -e 'tell application "Spotify" to activate'
12       sleep 2
13     fi
14@@ -413,9 +413,13 @@ function spotify() {
15         break ;;
16 
17       "quit"    )
18-        cecho "Quitting Spotify.";
19-        osascript -e 'tell application "Spotify" to quit';
20-        exit 1 ;;
21+        if [ "$(osascript -e 'application "Spotify" is running')" = "false" ]; then
22+          cecho "Spotify was not running."
23+        else
24+          cecho "Closing Spotify.";
25+          osascript -e 'tell application "Spotify" to quit';
26+        fi
27+        break ;;
28 
29       "next"    )
30         cecho "Going to next track." ;
31@@ -470,7 +474,7 @@ function spotify() {
32       "pos"   )
33         cecho "Adjusting Spotify play position."
34         osascript -e "tell application \"Spotify\" to set player position to $2";
35-        break;;
36+        break ;;
37 
38       "status" )
39         showStatus;