2020-04-27 06:47:36 +00:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
|
2020-10-14 07:02:48 +00:00
|
|
|
# symbola
|
|
|
|
set ICON_RECORDING 🎥
|
|
|
|
set ICON_MUSIC ♬
|
|
|
|
set ICON_MUTED 🔉
|
|
|
|
set ICON_VOLUME 🔊
|
|
|
|
set ICON_NIC 🖧
|
|
|
|
set ICON_WIFI 📡
|
|
|
|
set ICON_MEMORY 📈
|
|
|
|
set ICON_TEMPERATURE 🌡
|
|
|
|
set ICON_PLUGGED 🔌
|
|
|
|
set ICON_BATTERY 🔋
|
|
|
|
set ICON_DATETIME ⏲
|
|
|
|
|
|
|
|
# nerdfont
|
2020-10-14 12:36:39 +00:00
|
|
|
set ICON_RECORDING 辶
|
|
|
|
set ICON_MUSIC
|
|
|
|
set ICON_MUTED 'ﱝ '
|
|
|
|
set ICON_VOLUME ' '
|
|
|
|
set ICON_NIC ' '
|
|
|
|
set ICON_WIFI ' '
|
|
|
|
set ICON_MEMORY ' '
|
2020-10-14 08:05:23 +00:00
|
|
|
set ICON_TEMPERATURE
|
2020-10-14 12:36:39 +00:00
|
|
|
set ICON_PLUGGED ' '
|
|
|
|
set ICON_BATTERY_0 ' '
|
|
|
|
set ICON_BATTERY_1 ' '
|
|
|
|
set ICON_BATTERY_2 ' '
|
|
|
|
set ICON_BATTERY_3 ' '
|
|
|
|
set ICON_BATTERY_4 ' '
|
|
|
|
set ICON_DATETIME ' '
|
2020-10-14 07:02:48 +00:00
|
|
|
|
2020-04-27 06:47:36 +00:00
|
|
|
|
|
|
|
function update
|
2020-10-14 07:02:48 +00:00
|
|
|
if pgrep slock
|
|
|
|
return
|
|
|
|
end
|
|
|
|
set -x text
|
|
|
|
if test -f /tmp/recording.pid
|
|
|
|
set text $text $ICON_RECORDING
|
2020-04-27 06:47:36 +00:00
|
|
|
end
|
2020-10-14 07:02:48 +00:00
|
|
|
# mpd
|
|
|
|
if which mpc 1>/dev/null 2>&1
|
|
|
|
set music (mpc)
|
|
|
|
if string match -r playing "$music[2]" 1>/dev/null 2>&1
|
|
|
|
set text $text "$ICON_MUSIC $music[1]"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# volume
|
|
|
|
set vol (amixer get Master)
|
|
|
|
if string match -r '\[off\]' "$vol"
|
|
|
|
set text $text "$ICON_MUTED 0"
|
2020-04-27 06:47:36 +00:00
|
|
|
else
|
2020-10-14 07:02:48 +00:00
|
|
|
set v (string match -r '\[(\d+)%\]' $vol | tail -n 1)
|
|
|
|
set text $text "$ICON_VOLUME $v"
|
|
|
|
end
|
|
|
|
# network
|
|
|
|
for nic in (ls -d /sys/class/net/e*)
|
|
|
|
if grep up $nic/operstate >/dev/null
|
|
|
|
set speed (cat $nic/speed)M
|
|
|
|
set text $text "$ICON_NIC $speed"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
set wifi (grep "^\s*w" /proc/net/wireless | awk '{ print int($3 * 100 / 70) "%" }')
|
|
|
|
if test -n "$wifi"
|
|
|
|
set text $text "$ICON_WIFI $wifi"
|
2020-04-27 06:47:36 +00:00
|
|
|
end
|
2020-10-14 07:02:48 +00:00
|
|
|
# memory
|
|
|
|
set memory (free | awk '/^Mem:/ {print $3 "/" $2 "*" 100}' | math -s0)
|
|
|
|
set text $text "$ICON_MEMORY $memory%"
|
|
|
|
# cpu
|
|
|
|
set cpu (sensors | awk '/Core /{print $3}' | sort -r | head -n 1)
|
|
|
|
if test -n "$cpu"
|
|
|
|
set text $text "$ICON_TEMPERATURE $cpu"
|
|
|
|
end
|
|
|
|
# battery
|
|
|
|
set battery (cat /sys/class/power_supply/BAT0/capacity 2>/dev/null || echo "-1")
|
|
|
|
if test $battery -gt -1
|
|
|
|
set plugged (cat /sys/class/power_supply/AC/online)
|
|
|
|
if test $plugged -eq 1
|
|
|
|
set battery "$ICON_PLUGGED $battery%"
|
2020-10-14 12:36:39 +00:00
|
|
|
else if test -n "$ICON_BATTERY"
|
2020-10-14 07:02:48 +00:00
|
|
|
set battery "$ICON_BATTERY $battery%"
|
2020-10-14 12:36:39 +00:00
|
|
|
else if test -n "$ICON_BATTERY_0"
|
|
|
|
if test ""$battery -gt 90
|
2020-10-14 07:02:48 +00:00
|
|
|
set battery "$ICON_BATTERY_4 $battery%"
|
|
|
|
else if test $battery -gt 75
|
|
|
|
set battery "$ICON_BATTERY_3 $battery%"
|
|
|
|
else if test $battery -gt 50
|
|
|
|
set battery "$ICON_BATTERY_2 $battery%"
|
|
|
|
else if test $battery -gt 25
|
|
|
|
set battery "$ICON_BATTERY_1 $battery%"
|
|
|
|
else
|
|
|
|
set battery "$ICON_BATTERY_0 $battery%"
|
|
|
|
end
|
|
|
|
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")
|
|
|
|
set text $text "$ICON_DATETIME $dt"
|
|
|
|
set text (string join ' ' $text)
|
|
|
|
xsetroot -name " $text "
|
2020-04-27 06:47:36 +00:00
|
|
|
|
2020-10-14 07:02:48 +00:00
|
|
|
# prevent screen-saver when there is ongoing zoom metting
|
|
|
|
if xdotool search --name '^Zoom Meeting ID:'
|
|
|
|
xset s reset
|
|
|
|
end
|
2020-04-27 06:47:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function loop
|
2020-10-14 07:02:48 +00:00
|
|
|
while true
|
|
|
|
update
|
|
|
|
sleep 1
|
|
|
|
end
|
2020-04-27 06:47:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function start
|
2020-10-14 07:02:48 +00:00
|
|
|
set script (status -f)
|
|
|
|
$script loop &
|
2020-04-27 06:47:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function restart
|
2020-10-14 07:02:48 +00:00
|
|
|
pkill -f 'dwmbar loop'
|
|
|
|
start
|
2020-04-27 06:47:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
switch "$argv[1]"
|
2020-10-14 07:02:48 +00:00
|
|
|
case "update"
|
|
|
|
update
|
|
|
|
case "loop"
|
|
|
|
loop
|
|
|
|
case "start"
|
|
|
|
start
|
|
|
|
case "*"
|
|
|
|
restart
|
2020-04-27 06:47:36 +00:00
|
|
|
end
|