~tardypad/dotfiles

ref: 7dd5e02494e2821ff6b4fd5758a590ef03b5403b dotfiles/packages/i3blocks/scripts/music -rwxr-xr-x 862 bytes
7dd5e024 — Damien Tardy-Panis add mako package config 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env zsh

MUSIC_INFO=$(
  mpc status --format '[[%artist% / ]%title%]|[%file%]' 2> /dev/null
)

# only display something if the MPD is on
# and the songs queue is not empty
if [[ -z "${MUSIC_INFO}" \
    || $( mpc playlist | wc --lines ) -eq 0 ]]; then
  exit 0
fi


if echo "${MUSIC_INFO}" | grep --quiet '^\[playing\]'; then
  MUSIC_ICON=''
  MUSIC_TEXT=$(
    echo "${MUSIC_INFO}" \
      | head --lines 1 \
      | cut --characters -50
  )
elif echo "${MUSIC_INFO}" | grep --quiet '^\[paused\]'; then
  MUSIC_ICON=''
  MUSIC_TEXT='Paused'
else
  MUSIC_ICON=''
  MUSIC_TEXT='Stopped'
fi

# #HACK: sway bar seems to crash if a text to be displayed contains the character '&'
MUSIC_TEXT=$( echo "${MUSIC_TEXT}" | tr --delete '&' )

echo "<span foreground='#{color/base0A/hex}'>${MUSIC_ICON}</span> <span style='italic'>${MUSIC_TEXT}</span>"