dotfiles/suckless/config/dwm/dwmbar

107 lines
2.4 KiB
Plaintext
Raw Normal View History

2020-04-27 06:47:36 +00:00
#!/usr/bin/env fish
function update
if pgrep slock
return
end
2020-04-27 06:47:36 +00:00
set -x text
2020-09-29 04:32:04 +00:00
if test -f /tmp/recording.pid
2020-09-29 06:10:29 +00:00
set text $text "🎥"
2020-09-29 04:32:04 +00:00
end
2020-04-27 06:47:36 +00:00
# mpd
2020-09-29 10:21:37 +00:00
if which mpc 1>/dev/null 2>&1
2020-09-19 01:23:38 +00:00
set music (mpc)
2020-09-29 10:21:37 +00:00
if string match -r playing "$music[2]" 1>/dev/null 2>&1
2020-09-29 06:10:29 +00:00
set text $text "♬ $music[1]"
2020-09-19 01:23:38 +00:00
end
2020-04-27 06:47:36 +00:00
end
# volume
set vol (amixer get Master)
if string match -r '\[off\]' "$vol"
2020-09-29 10:21:37 +00:00
set text $text "🔉 0"
2020-04-27 06:47:36 +00:00
else
set v (string match -r '\[(\d+)%\]' $vol | tail -n 1)
2020-09-29 10:21:37 +00:00
set text $text "🔊 $v"
2020-04-27 06:47:36 +00:00
end
# network
for nic in (ls -d /sys/class/net/e*)
if grep up $nic/operstate > /dev/null
set speed (cat $nic/speed)M
2020-09-29 10:21:37 +00:00
set text $text "🖧 $speed"
2020-04-27 06:47:36 +00:00
end
end
set wifi (grep "^\s*w" /proc/net/wireless | awk '{ print int($3 * 100 / 70) "%" }')
if test -n "$wifi"
2020-09-29 10:21:37 +00:00
set text $text "📡 $wifi"
2020-04-27 06:47:36 +00:00
end
# memory
set memory (free | awk '/^Mem:/ {print $3 "/" $2 "*" 100}' | math -s0)
2020-09-29 10:21:37 +00:00
set text $text "📈 $memory%"
2020-04-27 06:47:36 +00:00
# cpu
set cpu (sensors | awk '/Core /{print $3}' | sort -r | head -n 1)
if test -n "$cpu"
2020-09-29 10:21:37 +00:00
set text $text "🌡 $cpu"
2020-04-27 06:47:36 +00:00
end
# battery
2020-09-19 01:23:38 +00:00
set battery (cat /sys/class/power_supply/BAT0/capacity 2>/dev/null || echo "-1")
2020-04-27 06:47:36 +00:00
if test "$battery" -gt -1
set plugged (cat /sys/class/power_supply/AC/online)
if test "$plugged" -eq 1
2020-09-29 10:21:37 +00:00
set battery "🔌 $battery%"
2020-04-27 06:47:36 +00:00
else
2020-09-29 10:21:37 +00:00
set battery "🔋 $battery%"
#if test $battery -gt 90
#set battery " $battery%"
#else if test $battery -gt 75
#set battery " $battery%"
#else if test $battery -gt 50
#set battery " $battery%"
#else if test $battery -gt 25
#set battery " $battery%"
#else
#set battery " $battery%"
#end
2020-04-27 06:47:36 +00:00
end
set text $text "$battery"
end
# | sed 's/Mon/一/; s/Tue/二/; s/Wed/三/; s/Thu/四/; s/Fri/五/; s/Sat/六/; s/Sun/日/;'
set dt (date +"%m-%d %H:%M %a")
2020-09-29 10:21:37 +00:00
set text $text "⏲ $dt"
2020-04-27 06:47:36 +00:00
set text (string join ' ' $text)
xsetroot -name " $text "
# prevent screen-saver when there is ongoing zoom metting
if xdotool search --name '^Zoom Meeting ID:'
xset s reset
end
end
function loop
while true
update
sleep 1
end
end
function start
set script (status -f)
$script loop &
end
function restart
pkill -f 'dwmbar loop'
start
end
switch "$argv[1]"
case "update"
update
case "loop"
loop
case "start"
start
case "*"
restart
end