-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmus
executable file
·72 lines (64 loc) · 2.17 KB
/
mus
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
# shellcheck disable=1090,2154,2086
playerctl metadata >/dev/null || exit 1
notif_identifier="i3b$(echo "$0" | tr '/' '\n' | tail -1)"
notif="notify-send -h string:x-canonical-private-synchronous:$notif_identifier"
. "${XDG_CACHE_HOME:-$HOME/.cache}/wal/colors.sh"
blockcolor=$color8
txtcolor=$color7
for player in mpd spotifyd spotify mpv; do
[ "$(playerctl -p $player status)" = "Playing" ] && {
artist="$(playerctl -p $player metadata artist)"
title="$(playerctl -p $player metadata title)"
current_player="-p $player "
break
}
done 2>/dev/null
# Silence any errors if a player can't be found.
[ "$current_player" ] || {
artist="$(playerctl metadata artist)"
title="$(playerctl metadata title)"
current_player=""
}
case $BLOCK_BUTTON in
1) # Left Click
playerctl ${current_player}previous
;;
2) # Middle Click
playerctl ${current_player}play-pause
;;
3) # Right Click
playerctl ${current_player}next
;;
4) # Scroll Up
playerctl ${current_player}position 5+
;;
5) # Scroll Down
playerctl ${current_player}position 5-
;;
8 | 9)
$notif \
-i "$(playerctl ${current_player}metadata | awk '/artUrl/{$1="";$2="";print}' | xargs)" \
"$(playerctl ${current_player}metadata | awk '/artist/{$1="";$2="";print}' | xargs)" \
"$(playerctl ${current_player}metadata | awk '/title/{$1="";$2="";print}' | xargs)"
;;
esac
# i3blocks doesn't seem to like ampersands
echo "$artist" | grep -q '&' && artist=$(echo "$artist" | sed 's/&/and/g')
echo "$title" | grep -q '&' && title=$(echo "$title" | sed 's/&/and/g')
# If no artist is found in the metadata, the current media is not a song
# or it is only generic media
printf "<b><span foreground='%s' background='%s'></span>" $blockcolor $color0
if [ -z "$artist" ]; then
printf "<span foreground='%s' background='%s'> %s </span>" \
$txtcolor $blockcolor "$title"
else
printf "<span foreground='%s' background='%s'> %s </span>" \
$color3 $blockcolor "$artist"
printf "<span foreground='%s' background='%s'>-</span>" \
$txtcolor $blockcolor
printf "<span foreground='%s' background='%s'> %s </span>" \
$color6 $blockcolor "$title"
fi
printf "<span foreground='%s' background='%s'></span></b>\n" \
$color0 $blockcolor