summaryrefslogtreecommitdiff
path: root/polybar/scripts/music-status.sh
blob: 229e0580b5e9ec4d9ff26e24ff1a4bdb604331da (plain)
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
34
35
36
37
38
#!/usr/bin/env bash
set -euo pipefail

if ! command -v playerctl >/dev/null 2>&1; then
  echo "n/a"
  exit 0
fi

status="$(playerctl status 2>/dev/null || true)"
if [ -z "$status" ]; then
  echo "off"
  exit 0
fi

artist="$(playerctl metadata artist 2>/dev/null || true)"
title="$(playerctl metadata title 2>/dev/null || true)"

if [ -n "$artist" ] && [ -n "$title" ]; then
  text="$artist - $title"
elif [ -n "$title" ]; then
  text="$title"
else
  text="$status"
fi

case "$status" in
  Playing)
    prefix="%{F#98971a}>%{F-}"
    ;;
  Paused)
    prefix="%{F#d79921}=%{F-}"
    ;;
  *)
    prefix="-"
    ;;
esac

printf '%s %s\n' "$prefix" "$(printf '%s' "$text" | cut -c 1-32)"