diff --git a/README.md b/README.md index 9e4b73e..8cc43e0 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A modular statusbar for DWM - [dwm_keyboard](#dwm_keyboard) - [dwm_resources](#dwm_resources) - [dwm_cmus](#dwm_cmus) + - [dwm_mpc](#dwm_mpc) - [dwm_date](#dwm_date) - [dwm_mail](#dwm_mail) - [dwm_weather](#dwm_weather) @@ -71,6 +72,12 @@ displays current cmus status, artist, track, position, duration, and shuffle [▶ The Unicorns - Tuff Ghost 0:43/2:56 🔀] ``` Dependencies: ```cmus``` +### dwm_mpc +displays current mpc status, artist, track, position, duration, and shuffle +``` +[▶ The Unicorns - Tuff Ghost 0:43/2:56 🔀] +``` +Dependencies: ```mpc``` ### dwm_date Displays the current date and time ``` diff --git a/bar-functions/dwm_mpc.sh b/bar-functions/dwm_mpc.sh new file mode 100755 index 0000000..770aeb8 --- /dev/null +++ b/bar-functions/dwm_mpc.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +# A dwm_bar function that shows the current artist, track, position, duration, and status from mpc +# Joe Standring +# GNU GPLv3 + +# Dependencies: mpc + +dwm_mpc () { + if ps -C mpd > /dev/null; then + ARTIST=$(mpc current -f %artist%) + TRACK=$(mpc current -f %title%) + POSITION=$(mpc status | grep "%)" | awk '{ print $3 }' | awk -F/ '{ print $1 }') + DURATION=$(mpc current -f %time%) + STATUS=$(mpc status | sed -n 2p | awk '{print $1;}') + SHUFFLE=$(mpc status | tail -n 1 | awk '{print $6}') + + if [ "$IDENTIFIER" = "unicode" ]; then + if [ "$STATUS" = "[playing]" ]; then + STATUS="▶" + else + STATUS="⏸" + fi + + if [ "$SHUFFLE" = "on" ]; then + SHUFFLE=" 🔀" + else + SHUFFLE="" + fi + else + if [ "$STATUS" = "[playing]" ]; then + STATUS="PLA" + else + STATUS="PAU" + fi + + if [ "$SHUFFLE" = "on" ]; then + SHUFFLE=" S" + else + SHUFFLE="" + fi + fi + + printf "%s%s %s - %s %s/%s%s%s" "$SEP1" "$STATUS" "$ARTIST" "$TRACK" "$POSITION" "$DURATION" "$SHUFFLE" "$SEP2" + fi +} + +dwm_mpc diff --git a/dwm_bar.sh b/dwm_bar.sh index 20dabf3..9b3790c 100755 --- a/dwm_bar.sh +++ b/dwm_bar.sh @@ -26,6 +26,7 @@ export SEP2="]" . "$DIR/bar-functions/dwm_alarm.sh" . "$DIR/bar-functions/dwm_transmission.sh" . "$DIR/bar-functions/dwm_cmus.sh" +. "$DIR/bar-functions/dwm_mpc.sh" . "$DIR/bar-functions/dwm_resources.sh" . "$DIR/bar-functions/dwm_battery.sh" . "$DIR/bar-functions/dwm_mail.sh" @@ -42,6 +43,6 @@ export SEP2="]" # Update dwm status bar every second while true do - xsetroot -name "$(dwm_countdown)$(dwm_alarm.sh)$(dwm_transmission)$(dwm_cmus)$(dwm_resources)$(dwm_battery)$(dwm_mail)$(dwm_backlight)$(dwm_alsa)$(dwm_pulse)$(dwm_weather)$(dwm_vpn)$(dwm_network)$(dwm_keyboard)$(dwm_ccurse)$(dwm_date)" + xsetroot -name "$(dwm_countdown)$(dwm_alarm.sh)$(dwm_transmission)$(dwm_cmus)$(dwm_mpc)$(dwm_resources)$(dwm_battery)$(dwm_mail)$(dwm_backlight)$(dwm_alsa)$(dwm_pulse)$(dwm_weather)$(dwm_vpn)$(dwm_network)$(dwm_keyboard)$(dwm_ccurse)$(dwm_date)" sleep 1 done