-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwm_status_bar
executable file
·148 lines (120 loc) · 4.59 KB
/
dwm_status_bar
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /bin/bash
delim="|"
while true; do
sleep=20
#-----------
# CMUS
#-----------
if pidof cmus >/dev/null ; then
sleep=1
all_info=$(cmus-remote -Q 2>/dev/null)
num=$(echo "${all_info}" | grep ' tracknumber ' | cut -d ' ' -f3-)
title=$(echo "${all_info}" | grep ' title ' | cut -d ' ' -f3-)
artist=$(echo "${all_info}" | grep ' artist ' | cut -d ' ' -f3-)
album=$(echo "${all_info}" | grep ' album ' | cut -d ' ' -f3-)
shuffle_status=$(echo "${all_info}" | grep ' shuffle ' | cut -d ' ' -f3)
# Get track position (seconds in) and duration and format for display with zero padding
position_info=$(echo "${all_info}" | grep 'position ' | cut -d ' ' -f2-)
duration_info=$(echo "${all_info}" | grep 'duration ' | cut -d ' ' -f2-)
position_mins=$(( position_info / 60 ))
position_secs=$(( position_info % 60 ))
position_formatted_mins=$(printf "%02d" $position_mins)
position_formatted_secs=$(printf "%02d" $position_secs)
duration_mins=$(( duration_info / 60 ))
duration_secs=$(( duration_info % 60 ))
duration_formatted_mins=$(printf "%02d" $duration_mins)
duration_formatted_secs=$(printf "%02d" $duration_secs)
if [ "$shuffle_status" == "true" ] ; then
shuffle_status=" 🔀"
else
unset shuffle_status
fi
track_time="$position_formatted_mins:$position_formatted_secs/$duration_formatted_mins:$duration_formatted_secs"
cmus=" $title - $artist [$album] ($track_time)$shuffle_status $delim"
else
unset cmus
fi
#-----------
# VPN
#-----------
if ip address | grep mullvad >/dev/null ; then
vpn=" 🔒 $delim"
else
unset vpn
fi
#-----------
# TORRENTS
#-----------
if pidof transmission-daemon >/dev/null ; then
torrents_info=$(transmission-remote --list)
id_list=$(echo "$torrents_info" | sed -e '1d;$d;s/^ *//' | cut -f1 -d' ')
downloading=0
seeding=0
seeded=0
for torrent_id in $id_list ; do
torrent_id=$(echo "$torrent_id" | sed 's:*::')
info=$(transmission-remote --torrent "$torrent_id" --info)
percentage=$(echo "$info" | grep "Percent Done: *" | awk '{print $3}' | awk '{$1=$1}1')
ratio=$(echo "$info" | grep "Ratio: *" | awk '{print $2}' | awk '{$1=$1}1')
if [ "$percentage" = "100%" ] ; then
first_digit="$(echo "$ratio" | cut -c 1)"
if [ "$first_digit" -gt 0 ] ; then
seeded=$(($seeded + 1))
else
seeding=$(($seeding + 1))
fi
else
downloading=$(($downloading + 1))
fi
done;
overall_info=$(echo "$torrents_info" | grep Sum:)
down_speed="$(echo "$overall_info" | awk '{ print $5 }' | awk -F"." '{ print $1 }')"
up_speed="$(echo "$overall_info" | awk '{ print $4 }' | awk -F"." '{ print $1 }')"
if [ "$downloading" = 0 ] ; then
unset downloading
else
downloading=" 🔽"$downloading" ("$down_speed")"
fi
if [ "$seeding" = 0 ] ; then
unset seeding
else
seeding=" 🔼"$seeding" ("$up_speed")"
fi
if [ "$seeded" = 0 ] ; then
unset seeded
else
seeded=" ✔️ "$seeded""
fi
torrents=""$downloading""$seeding""$seeded" $delim"
else
unset torrents
fi
#-----------
# VOLUME
#-----------
if [[ $(grep -c "Pin-ctls: 0x00" "/proc/asound/card0/codec#0") == 1 ]] ; then
percentage="$(amixer sget Master | awk -F"[][]" '/dB/ { print $2 }')"
if [[ $(amixer sget Master | awk -F"[][]" '/dB/ { print $6 }') == 'off' ]] ; then
volume=" 🔇 $delim"
elif [ "$percentage" != "100%" ] ; then
volume=" 🔊 $percentage $delim"
else
unset volume
fi
else
percentage="$(amixer sget Headphone | awk -F"[][]" '/dB/ { print $2;exit; }')"
if [[ $(amixer sget Headphone | awk -F"[][]" '/dB/ { print $6;exit; }') == 'off' ]] ; then
volume=" 🎧 🔇 $delim"
elif [ "$percentage" != "100%" ] ; then
volume=" 🎧 $percentage $delim"
else
unset volume
fi
fi
#-----------
# DATE
#-----------
date=" $(date +%a-%d-%b-%R | tr '-' ' ') "
xsetroot -name "$delim$cmus$torrents$vpn$volume$date"
sleep $sleep
done