-
Notifications
You must be signed in to change notification settings - Fork 0
/
now_playing
executable file
·91 lines (77 loc) · 1.5 KB
/
now_playing
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# Print now playing from mpd via mpc
# use -n to send notification
# use -p to paste to cursor
#
# Dependencies:
# * mpc
# * notify-send (only for -n)
# * xdotool (only for -p)
# notify-send settings:
ns_urgency="normal" #low/normal/critical
ns_timeexpire="10"
ns_appname=""
ns_summary="mpd now playing:"
HELP_TAB=" "
HELP="Now Playing Script:;\
$HELP_TAB-n for notify-send;\
$HELP_TAB-p for paste to cursor via xdotool;\
$HELP_TAB-h for help"
_show_help () {
IFS=";"
for hl in $HELP; do
echo "$hl"
done
}
_notify_send () {
if ! [[ -z "${ns_urgency// }" ]]; then
urg="-u $ns_urgency"
else
urg=""
fi
if ! [[ -z "${ns_timeexpire// }" ]]; then
te="-t $ns_timeexpire"
else
te=""
fi
if ! [[ -z "${ns_appname// }" ]]; then
appn="-a $ns_appname"
else
appn=""
fi
if ! [[ -z "${ns_summary// }" ]]; then
sum="$ns_summary"
else
sum=""
fi
notify-send $urg $te $appn "$sum" "$@"
}
if mpc status | awk 'NR==2' | grep playing >/dev/null; then
np=$(mpc current)
else
np="Stopped"
fi
if [[ $# -gt 1 ]]; then
echo "Too many arguments given, only one expected."
_show_help
exit 1
fi
if [[ $# -eq 0 ]]; then
echo "Now Playing: $np"
exit 0
fi
if [[ $1 == '-n' ]]; then
_notify_send "$np"
exit 0
elif [[ $1 == '-p' ]]; then
sleep 0.1
xdotool type --delay 2 "Now Playing: $np"
exit 0
elif [[ $1 == '-h' ]]; then
_show_help
exit 0
else
echo "Invalid argument."
_show_help
fi
#EOF