aboutsummaryrefslogtreecommitdiff
path: root/scripts/.local/bin/personal/musctl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/.local/bin/personal/musctl')
-rwxr-xr-xscripts/.local/bin/personal/musctl57
1 files changed, 31 insertions, 26 deletions
diff --git a/scripts/.local/bin/personal/musctl b/scripts/.local/bin/personal/musctl
index cca7b8d..6bfbd16 100755
--- a/scripts/.local/bin/personal/musctl
+++ b/scripts/.local/bin/personal/musctl
@@ -1,33 +1,38 @@
#!/bin/bash
-STATE="$(mpc | grep -o playing)"
-NAME="$(basename "$(mpc current)")"
+# A script to manage the music player daemon (mpd) on my system
+# Depends on: mpd, playerctl, libnotify
+# By David Penkowoj, 2024-09-16
-notify() {
- if [[ -n "$STATE" ]]; then
- notify-send "Currently playing" "${NAME%.*}"
- else
- notify-send "MPD is currently paused"
- fi
+music_state="$(mpc | grep -o playing)"
+music_name="$(basename "$(mpc current)")"
+
+notify_music() {
+ if [[ -n "$music_state" ]]; then
+ notify-send "Currently playing" "${music_name%.*}"
+ else
+ notify-send "MPD is currently paused"
+ fi
}
case "$1" in
- "previous")
- mpc -q prev
- playerctl -s previous
- ;;
- "toggle")
- mpc -q toggle
- playerctl -s play-pause
- ;;
- "next")
- mpc -q next
- playerctl -s next
- ;;
- "notify")
- notify
- ;;
- *)
- echo "[ Error ] Unknown command"
- ;;
+ "previous")
+ mpc -q prev
+ playerctl -s previous
+ ;;
+ "toggle")
+ mpc -q toggle
+ playerctl -s play-pause
+ ;;
+ "next")
+ mpc -q next
+ playerctl -s next
+ ;;
+ "notify")
+ notify_music
+ ;;
+ *)
+ printf "[ Error ] Usage: musctl [previous|toggle|next|notify]"
+ exit 1
+ ;;
esac