diff --git a/m b/m index 0992288..ab8e1b7 100755 --- a/m +++ b/m @@ -27,23 +27,23 @@ get_version(){ return 1 fi - local git_tag=$(git -C ${MCLI_PATH} describe --tags --exact-match HEAD 2>/dev/null) - local git_hash=$(git -C ${MCLI_PATH} rev-parse --short HEAD 2>/dev/null) + local git_tag=$(git -C "${MCLI_PATH}" describe --tags --exact-match HEAD 2>/dev/null) + local git_hash=$(git -C "${MCLI_PATH}" rev-parse --short HEAD 2>/dev/null) if [ -n "$git_tag" ]; then echo "m-cli version: $git_tag ($git_hash)" - else + else echo "m-cli version: $git_hash (not tagged)" fi } update_mcli(){ confirm "Do you want to update m-cli? [y/n]: " || exit 0 - INSTALL_DIR=${MCLI_PATH} bash ${MCLI_PATH}/install.sh + INSTALL_DIR="${MCLI_PATH}" bash "${MCLI_PATH}/install.sh" } uninstall_mcli(){ confirm "Do you want to uninstall m-cli? [y/n]: " || exit 0 - sudo rm -rf ${MCLI_PATH} 2>/dev/null \ + sudo rm -rf "${MCLI_PATH}" 2>/dev/null \ sudo rm -f "/usr/local/bin/m" 2>/dev/null \ sudo rm -f "${HOME}/.local/bin/m" 2>/dev/null \ echo "Done !" @@ -65,7 +65,7 @@ Options: COMMANDS: __EOF__ - for i in "$MCLI_PATH"/plugins/*; do + for i in "${MCLI_PATH}"/plugins/*; do [ -f "$i" ] && [ ! -L "$i" ] && echo " ${i##*/}" done } @@ -89,6 +89,6 @@ esac COMMAND=${1} shift; -[ ! -f ${MCLI_PATH}/plugins/${COMMAND} ] && usage && exit 1 +[ ! -f "${MCLI_PATH}/plugins/${COMMAND}" ] && usage && exit 1 -${MCLI_PATH}/plugins/${COMMAND} "$@" +"${MCLI_PATH}/plugins/${COMMAND}" "$@" diff --git a/plugins/itunes b/plugins/itunes index 2f83f3a..3054797 100755 --- a/plugins/itunes +++ b/plugins/itunes @@ -1,12 +1,12 @@ #!/usr/bin/env bash -MAC_VERSION=`/usr/bin/sw_vers -productVersion | /usr/bin/awk -F. '{printf "%d%03d%03d\n", $1, $2, $3}'` +MAC_MAJOR=$(/usr/bin/sw_vers -productVersion | /usr/bin/awk -F. '{print $1}') +MAC_MINOR=$(/usr/bin/sw_vers -productVersion | /usr/bin/awk -F. '{print $2}') music_cmd="iTunes" # check if >= Catalina (10.15) # iTunes was renamed to Music -if [ `echo "${MAC_VERSION} > 10015000" | bc -l` ] -then +if [ "${MAC_MAJOR}" -gt 10 ] || { [ "${MAC_MAJOR}" -eq 10 ] && [ "${MAC_MINOR}" -ge 15 ]; }; then music_cmd="Music" fi @@ -21,11 +21,13 @@ Options: --status Show current status --play Play current track --playpause Play/pause current track + --toggle Toggle play/pause current track --stop Stop current track --pause Pause current track --next Play next track --prev Play previous track --mute Mute ${music_cmd} + --unmute Unmute ${music_cmd} --vol LEVEL Set application volume to LEVEL (0-100) --quit Quit ${music_cmd} __EOF__ @@ -57,41 +59,41 @@ set_volume(){ } case $1 in - --help) + --help|help|-h) help ;; - --status) + --status|status) show_status ;; - --play) + --play|play) osascript -e "tell application \"${music_cmd}\" to play" ;; - --playpause) + --playpause|--toggle|playpause|toggle|play/pause) osascript -e "tell application \"${music_cmd}\" to playpause" ;; - --pause) + --pause|pause) osascript -e "tell application \"${music_cmd}\" to pause" ;; - --next) + --next|next) osascript -e "tell application \"${music_cmd}\" to next track" ;; - --prev) + --prev|prev) osascript -e "tell application \"${music_cmd}\" to previous track" ;; - --mute) + --mute|mute) osascript -e "tell application \"${music_cmd}\" to set mute to true" ;; - --unmute) + --unmute|unmute) osascript -e "tell application \"${music_cmd}\" to set mute to false" ;; - --vol) + --vol|vol) shift set_volume "$@" ;; - --stop) + --stop|stop) osascript -e "tell application \"${music_cmd}\" to stop" ;; - --quit) + --quit|quit) osascript -e "tell application \"${music_cmd}\" to quit" ;; *) diff --git a/tests/test_itunes.sh b/tests/test_itunes.sh new file mode 100644 index 0000000..8cebe0b --- /dev/null +++ b/tests/test_itunes.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bats + +# Tests for plugins/itunes (and plugins/music symlink) + +PLUGIN="./plugins/itunes" +MUSIC_PLUGIN="./plugins/music" + +@test "itunes --help displays --toggle option" { + run $PLUGIN --help + [ "$status" -eq 0 ] + [[ "$output" == *"Usage: m Music"* ]] || [[ "$output" == *"Usage: m iTunes"* ]] + [[ "$output" == *"--toggle"* ]] + [[ "$output" == *"--playpause"* ]] + [[ "$output" == *"--unmute"* ]] +} + +@test "music --help displays --toggle option" { + run $MUSIC_PLUGIN --help + [ "$status" -eq 0 ] + [[ "$output" == *"--toggle"* ]] +} + +@test "itunes toggle option handling" { + run $PLUGIN --help + [ "$status" -eq 0 ] +}