-
Notifications
You must be signed in to change notification settings - Fork 1
/
mocinfo.sh
executable file
·99 lines (82 loc) · 2.33 KB
/
mocinfo.sh
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
92
93
94
95
96
97
98
99
#!/bin/bash
#By Adam Hallgat (https://github.com/hallgat89/)
getwid2 ()
{
a=`xdotool getactivewindow` &>/dev/null || :
printf 0x%x $a #convert to wmctrl format
}
#char repeater
repl() {
if [ "$2" -gt "0" ]
then
x=$(($2-1))
printf "$1"'%.s' $(eval "echo {0.."$(($x))"}");
else
echo ""
fi
}
getmopp ()
{
#gets state of moc player, or returns OFF
mocs=`mocp -Q %state &>/dev/null || echo OFF`
if [ "$mocs" == "PLAY" ]
then
outstring="▶ " # play symbol
elif [ "$mocs" == "PAUSE" ]
then
outstring="║ " # pause symbol
elif [ "$mocs" == "STOP" ]
then
outstring="■ ░░░░░░░░░░ -" # stop symbol, empty bar
fi
if [ "$mocs" == "PLAY" -o "$mocs" == "PAUSE" ]
then
mocpcs=`mocp -Q %cs` # current seconds
mocpts=`mocp -Q %ts` # total seconds (can be empty - online radio)
if [ -z "$mocpts" ]
then
#web radio
outstring="▼ " #web symbol
ec="`mocp -Q %b`kbps" #speed
ec2=""
#ec2=" `mocp -Q %r`kHz" #kHz
else
percent=`echo "scale=0; ($mocpcs*100/$mocpts)/10" | bc` #0-9
ec=$(repl '█' $((1 + $percent)) ) # loaded █
ec2=$(repl '░' $((9 - $percent)) ) # empty ░
fi
outstring="$outstring$ec$ec2 -"
fi
echo $outstring
}
set -e
function cleanup {
#restore original window title on exit (or crash)
wmctrl -ir "$WID" -T "$WIT" &>/dev/null || :
}
trap cleanup EXIT
WID=$(getwid2) #windowid
WIT=`xdotool getactivewindow getwindowname` &>/dev/null || : #window title
CWIT=$WIT #this will store the current window title
while [ "1" -eq "1" ]
do
mocinfo=`getmopp` # time or moc info
NWID=$(getwid2)
if [ "$NWID" != "$WID" ]
then
#window changed
wmctrl -ir "$WID" -T "$WIT" &>/dev/null || :
WID=$(getwid2)
WIT=`xdotool getactivewindow getwindowname` &>/dev/null || :
fi
TWIT=`xdotool getactivewindow getwindowname` &>/dev/null || :
if [ "$TWIT" != "$CWIT" ]
then
#echo "title changed"
WIT=$TWIT
fi
#update title
CWIT="$mocinfo$WIT"
wmctrl -ir "$WID" -T "$CWIT" &>/dev/null || :
sleep 1
done