diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2019-09-11 18:19:51 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2019-09-11 18:19:51 -0600 |
commit | d676c1553254309beca5bb9a8edb43fbe09a7169 (patch) | |
tree | d0bb04b6487e6fedbb2b2370a894fccd19d4c567 /plugins/osx | |
parent | fb141c2257f648cd29b64cbd3f2ca9123f6e427f (diff) | |
parent | ddd359dd668f448856438304bedfe952d1749efd (diff) | |
download | zsh-d676c1553254309beca5bb9a8edb43fbe09a7169.tar.gz zsh-d676c1553254309beca5bb9a8edb43fbe09a7169.tar.bz2 zsh-d676c1553254309beca5bb9a8edb43fbe09a7169.zip |
Merge remote-tracking branch 'orig/master'
Diffstat (limited to 'plugins/osx')
-rw-r--r-- | plugins/osx/README.md | 2 | ||||
-rw-r--r-- | plugins/osx/osx.plugin.zsh | 53 | ||||
-rw-r--r-- | plugins/osx/spotify | 64 |
3 files changed, 101 insertions, 18 deletions
diff --git a/plugins/osx/README.md b/plugins/osx/README.md index 3559dee02..4595ee319 100644 --- a/plugins/osx/README.md +++ b/plugins/osx/README.md @@ -18,7 +18,7 @@ This application makes use of the following third party scripts: [shpotify](https://github.com/hnarayanan/shpotify) -Copyright (c) 2012–2017 [Harish Narayanan](https://harishnarayanan.org/). +Copyright (c) 2012–2019 [Harish Narayanan](https://harishnarayanan.org/). Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index a1c73a184..eb3c4fb7a 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -51,6 +51,17 @@ EOF end tell end tell EOF + elif [[ "$the_app" == 'Hyper' ]]; then + osascript >/dev/null <<EOF + tell application "System Events" + tell process "Hyper" to keystroke "t" using command down + end tell + delay 1 + tell application "System Events" + keystroke "${command}" + key code 36 #(presses enter) + end tell +EOF else echo "tab: unsupported terminal app: $the_app" @@ -91,6 +102,19 @@ EOF end tell end tell EOF + + elif [[ "$the_app" == 'Hyper' ]]; then + osascript >/dev/null <<EOF + tell application "System Events" + tell process "Hyper" + tell menu item "Split Vertically" of menu "Shell" of menu bar 1 + click + end tell + end tell + delay 1 + keystroke "${command} \n" + end tell +EOF else echo "$0: unsupported terminal app: $the_app" >&2 @@ -132,6 +156,19 @@ EOF end tell EOF + elif [[ "$the_app" == 'Hyper' ]]; then + osascript >/dev/null <<EOF + tell application "System Events" + tell process "Hyper" + tell menu item "Split Horizontally" of menu "Shell" of menu bar 1 + click + end tell + end tell + delay 1 + keystroke "${command} \n" + end tell +EOF + else echo "$0: unsupported terminal app: $the_app" >&2 false @@ -199,7 +236,19 @@ function itunes() { opt="$opt track" ;; vol) - opt="set sound volume to $1" #$1 Due to the shift + local new_volume volume=$(osascript -e 'tell application "iTunes" to get sound volume') + if [[ $# -eq 0 ]]; then + echo "Current volume is ${volume}." + return 0 + fi + case $1 in + up) new_volume=$((volume + 10 < 100 ? volume + 10 : 100)) ;; + down) new_volume=$((volume - 10 > 0 ? volume - 10 : 0)) ;; + <0-100>) new_volume=$1 ;; + *) echo "'$1' is not valid. Expected <0-100>, up or down." + return 1 ;; + esac + opt="set sound volume to ${new_volume}" ;; playlist) # Inspired by: https://gist.github.com/nakajijapan/ac8b45371064ae98ea7f @@ -262,7 +311,7 @@ EOF echo "\tmute|unmute\tcontrol volume set" 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 "\tvol [0-100|up|down]\tGet or set the volume. 0 to 100 sets the volume. 'up' / 'down' increases / decreases by 10 points. No argument displays current volume." echo "\tplaying|status\tShow what song is currently playing in iTunes." echo "\tplaylist [playlist name]\t Play specific playlist" echo "\thelp\tshow this message and exit" diff --git a/plugins/osx/spotify b/plugins/osx/spotify index b4215dbe7..39f8e0437 100644 --- a/plugins/osx/spotify +++ b/plugins/osx/spotify @@ -1,7 +1,7 @@ #!/usr/bin/env bash function spotify() { -# Copyright (c) 2012--2018 Harish Narayanan <mail@harishnarayanan.org> +# Copyright (c) 2012--2019 Harish Narayanan <mail@harishnarayanan.org> # # Contains numerous helpful contributions from Jorge Colindres, Thomas # Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin @@ -70,7 +70,7 @@ showHelp () { echo; echo " next # Skips to the next song in a playlist."; echo " prev # Returns to the previous song in a playlist."; - echo " replay # Replays the current track from the begining."; + echo " replay # Replays the current track from the beginning."; echo " pos <time> # Jumps to a time (in secs) in the current song."; echo " pause # Pauses (or resumes) Spotify playback."; echo " stop # Stops playback."; @@ -82,6 +82,9 @@ showHelp () { echo " vol [show] # Shows the current Spotify volume."; echo; echo " status # Shows the current player status."; + echo " status artist # Shows the currently playing artist."; + echo " status album # Shows the currently playing album."; + echo " status track # Shows the currently playing track."; echo; echo " share # Displays the current song's Spotify URL and URI." echo " share url # Displays the current song's Spotify URL and copies it to the clipboard." @@ -99,12 +102,21 @@ cecho(){ echo $bold$green"$1"$reset; } +showArtist() { + echo `osascript -e 'tell application "Spotify" to artist of current track as string'`; +} + +showAlbum() { + echo `osascript -e 'tell application "Spotify" to album of current track as string'`; +} + +showTrack() { + echo `osascript -e 'tell application "Spotify" to name of current track as string'`; +} + showStatus () { state=`osascript -e 'tell application "Spotify" to player state as string'`; cecho "Spotify is currently $state."; - artist=`osascript -e 'tell application "Spotify" to artist of current track as string'`; - album=`osascript -e 'tell application "Spotify" to album of current track as string'`; - track=`osascript -e 'tell application "Spotify" to name of current track as string'`; duration=`osascript -e 'tell application "Spotify" set durSec to (duration of current track / 1000) as text set tM to (round (durSec / 60) rounding down) as text @@ -128,7 +140,7 @@ showStatus () { end tell return nowAt'`; - echo -e $reset"Artist: $artist\nAlbum: $album\nTrack: $track \nPosition: $position / $duration"; + echo -e $reset"Artist: $(showArtist)\nAlbum: $(showAlbum)\nTrack: $(showTrack) \nPosition: $position / $duration"; } if [ $# = 0 ]; then @@ -223,18 +235,18 @@ while [ $# -gt 0 ]; do results=$( \ curl -s -G $SPOTIFY_SEARCH_API --data-urlencode "q=$Q" -d "type=playlist&limit=10&offset=0" -H "Accept: application/json" -H "Authorization: Bearer ${SPOTIFY_ACCESS_TOKEN}" \ - | grep -E -o "spotify:user:[a-zA-Z0-9_]+:playlist:[a-zA-Z0-9]+" -m 10 \ + | grep -E -o "spotify:playlist:[a-zA-Z0-9]+" -m 10 \ ) count=$( \ - echo "$results" | grep -c "spotify:user" \ + echo "$results" | grep -c "spotify:playlist" \ ) if [ "$count" -gt 0 ]; then random=$(( $RANDOM % $count)); SPOTIFY_PLAY_URI=$( \ - echo "$results" | awk -v random="$random" '/spotify:user:[a-zA-Z0-9]+:playlist:[a-zA-Z0-9]+/{i++}i==random{print; exit}' \ + echo "$results" | awk -v random="$random" '/spotify:playlist:[a-zA-Z0-9]+/{i++}i==random{print; exit}' \ ) fi;; @@ -295,7 +307,7 @@ while [ $# -gt 0 ]; do "quit" ) cecho "Quitting Spotify."; osascript -e 'tell application "Spotify" to quit'; - exit 1 ;; + exit 0 ;; "next" ) cecho "Going to next track." ; osascript -e 'tell application "Spotify" to next track'; @@ -346,7 +358,7 @@ while [ $# -gt 0 ]; do echo " vol down # Decreases the volume by 10%."; echo " vol [amount] # Sets the volume to an amount between 0 and 100."; echo " vol # Shows the current Spotify volume."; - break + exit 1; fi osascript -e "tell application \"Spotify\" to set sound volume to $newvol"; @@ -365,7 +377,25 @@ while [ $# -gt 0 ]; do break ;; "status" ) - showStatus; + if [ $# != 1 ]; then + # There are additional arguments, a status subcommand + case $2 in + "artist" ) + showArtist; + break ;; + + "album" ) + showAlbum; + break ;; + + "track" ) + showTrack; + break ;; + esac + else + # status is the only param + showStatus; + fi break ;; "info" ) @@ -428,16 +458,20 @@ while [ $# -gt 0 ]; do cecho "Spotify URI: $uri"; echo -n $uri | pbcopy fi - break;; + break ;; "pos" ) cecho "Adjusting Spotify play position." osascript -e "tell application \"Spotify\" to set player position to $2"; - break;; + break ;; - "help" | * ) + "help" ) showHelp; break ;; + * ) + showHelp; + exit 1; + esac done } |