7f66a070a4be1ae797151e761f9eaaf3ef8549a8

Author
Pete Johns <johnsyweb@users.noreply.github.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

osx: add more arguments to `itunes vol` command (#7845)

- Get the iTunes volume without an argument
- Shift up / down iTunes volume

Diff

 1diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
 2index 7deed0ba630052aefeea4030e48226d2f0a92f87..eb3c4fb7a185b228a56688f125f02c54ee14e7d4 100644
 3--- a/plugins/osx/osx.plugin.zsh
 4+++ b/plugins/osx/osx.plugin.zsh
 5@@ -236,7 +236,19 @@ function itunes() {
 6 			opt="$opt track"
 7 			;;
 8 		vol)
 9-			opt="set sound volume to $1" #$1 Due to the shift
10+			local new_volume volume=$(osascript -e 'tell application "iTunes" to get sound volume')
11+			if [[ $# -eq 0 ]]; then
12+				echo "Current volume is ${volume}."
13+				return 0
14+			fi
15+			case $1 in
16+				up) new_volume=$((volume + 10 < 100 ? volume + 10 : 100)) ;;
17+				down) new_volume=$((volume - 10 > 0 ? volume - 10 : 0)) ;;
18+				<0-100>) new_volume=$1 ;;
19+				*) echo "'$1' is not valid. Expected <0-100>, up or down."
20+				   return 1 ;;
21+			esac
22+			opt="set sound volume to ${new_volume}"
23 			;;
24 		playlist)
25 		# Inspired by: https://gist.github.com/nakajijapan/ac8b45371064ae98ea7f
26@@ -299,7 +311,7 @@ EOF
27 			echo "\tmute|unmute\tcontrol volume set"
28 			echo "\tnext|previous\tplay next or previous track"
29 			echo "\tshuf|shuffle [on|off|toggle]\tSet shuffled playback. Default: toggle. Note: toggle doesn't support the MiniPlayer."
30-			echo "\tvol\tSet the volume, takes an argument from 0 to 100"
31+			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."
32 			echo "\tplaying|status\tShow what song is currently playing in iTunes."
33 			echo "\tplaylist [playlist name]\t Play specific playlist"
34 			echo "\thelp\tshow this message and exit"