diff --git a/arch-config/.config/polybar/i3config.ini b/arch-config/.config/polybar/i3config.ini index fa6c77ac..20b75eb2 100755 --- a/arch-config/.config/polybar/i3config.ini +++ b/arch-config/.config/polybar/i3config.ini @@ -84,7 +84,7 @@ font-5 = Iosevka:style=bold:size=16;3 modules-left = full sysmenu full i3 full left-top right-bot full xwindow full left-top modules-center = -modules-right = right-top full date battery full left-bot right-top +modules-right = right-top full player-cmus full left-bot right-top full date battery full left-bot right-top tray-detached = false tray-offset-x = 0 diff --git a/arch-config/.config/polybar/modules/modules.ini b/arch-config/.config/polybar/modules/modules.ini index 1d2eb537..e40b852e 100755 --- a/arch-config/.config/polybar/modules/modules.ini +++ b/arch-config/.config/polybar/modules/modules.ini @@ -96,6 +96,20 @@ click-left = ~/.config/polybar/scripts/powermenu ################################################################################ +[module/player-cmus] +type = custom/script +exec = ~/.config/polybar/scripts/player-cmus.sh +interval = 5 +content-background = ${colors.modbackground} +format-background = ${colors.modbackground} +click-left = cmus-remote -u & +click-right = cmus-remote -n & +click-middle = cmus-remote -r & + + +################################################################################ + + [module/backlight] ;https://github.com/jaagr/polybar/wiki/Module:-backlight diff --git a/arch-config/.config/polybar/scripts/player-cmus.sh b/arch-config/.config/polybar/scripts/player-cmus.sh new file mode 100755 index 00000000..108cc75d --- /dev/null +++ b/arch-config/.config/polybar/scripts/player-cmus.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# from https://github.com/polybar/polybar-scripts/tree/master/polybar-scripts/player-cmus + +if info=$(cmus-remote -Q 2> /dev/null); then + status=$(echo "$info" | grep -v "set " | grep -v "tag " | grep "status " | cut -d ' ' -f 2) + + if [ "$status" = "playing" ] || [ "$status" = "paused" ] || [ "$status" = "stopped" ]; then + title=$(echo "$info" | grep -v 'set ' | grep " title " | cut -d ' ' -f 3-) + artist=$(echo "$info" | grep -v 'set ' | grep " artist " | cut -d ' ' -f 3-) + position=$(echo "$info" | grep -v "set " | grep -v "tag " | grep "position " | cut -d ' ' -f 2) + duration=$(echo "$info" | grep -v "set " | grep -v "tag " | grep "duration " | cut -d ' ' -f 2) + + if [ "$artist" ] || [ "$title" ]; then + if [ "$duration" -ge 0 ]; then + pos_minutes=$(printf "%02d" $((position / 60))) + pos_seconds=$(printf "%02d" $((position % 60))) + + dur_minutes=$(printf "%02d" $((duration / 60))) + dur_seconds=$(printf "%02d" $((duration % 60))) + + info_string="| $pos_minutes:$pos_seconds / $dur_minutes:$dur_seconds" + fi + + info_string="$artist - $title $info_string" + + if [ "$status" = "playing" ]; then + echo "#1 $info_string" + elif [ "$status" = "paused" ]; then + echo "#2 $info_string" + elif [ "$status" = "stopped" ]; then + echo "#3 $info_string" + else + echo "" + fi + else + echo "" + fi + else + echo "" + fi +else + echo "" +fi