Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions m
Original file line number Diff line number Diff line change
Expand Up @@ -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 !"
Expand All @@ -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
}
Expand All @@ -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}" "$@"
32 changes: 17 additions & 15 deletions plugins/itunes
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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__
Expand Down Expand Up @@ -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"
;;
*)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_itunes.sh
Original file line number Diff line number Diff line change
@@ -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 ]
}