Wrote a couple scripts using FIFO pipes, stole the start of an idea from here in the xmonad module.
These will likely be included in the next release but for anyone wanting to give them a try, feel free.
I’ve obviously done basic testing with them and there shouldn’t be any issues (though you never know :P).
UPDATE: I made a change to the update script and added the use of inotifywait
it’s much more efficient this way while also being able to update as soon as the system database is changed, it will still work fine without but I had to use $(stat)
subshells to get a similar effect, so I recommend installing inotify-tools
if you don’t already have it.
UPDATE 2: I added an empty echo to clear the pipe when no updates are present, otherwise polybar just keeps drawing whatever was there last. This is currently untested though.
UPDATE 3: Fixed refresh after running a package operation.
network
script (copy to ~/bin/check-network
)
#!/bin/bash
# somewhat deamon network state icon
# written by Nathaniel Maia, 2019
wl=''
eth=''
dc='\|/-'
[ -p /tmp/.network_status ] || mkfifo /tmp/.network_status
# loop and dump info to the pipe
while true; do
until { ping -c 1 'archlinux.org' || ping -c 1 'archlabslinux.com'; } >/dev/null 2>&1; do
for (( i=0; i < ${#dc}; i++ )); do
echo "${dc:$i:1}" >/tmp/.network_status # spinning character
sleep 0.25
done
done
if ip link | grep -q '[0-9]:\se.*:.*state UP'; then
echo "$eth" >/tmp/.network_status
else
echo "$wl" >/tmp/.network_status
fi
sleep 300 # only recheck every 5m to save some cpu time
done
module (add to ~/.config/polybar/modules.conf
)
[module/network]
type = custom/script
exec = tail -F /tmp/.network_status
exec-if = [ -p /tmp/.network_status ]
tail = true
click-left = networkmanager_dmenu &
click-right = networkmanager_dmenu &
label-padding = 1
updates
script (copy to ~/bin/check-update
)
#!/bin/bash
# somewhat deamon update count + icon
# written by Nathaniel Maia, 2019
ICON=""
if ! hash checkupdates inotifywait >/dev/null 2>&1; then
echo 'error: check-update: requires "pacman-contrib" and "inotify-tools" installed' >&2
exit 1
fi
[ -p /tmp/.update_status ] || mkfifo /tmp/.update_status
# wait until were connected
until ping -c 1 'archlinux.org' >/dev/null 2>&1 || ping -c 1 'archlabslinux.com' >/dev/null 2>&1; do
sleep 10
done
# loop and dump info to the pipe
while true; do
if (( ( COUNT = $(checkupdates 2>/dev/null | wc -l) ) > 0 )); then
echo "$COUNT $ICON" >/tmp/.update_status
# recheck when the log is written to or after 1.5 hours
inotifywait -q -q -t 5000 -e close_write /var/log/pacman.log
sleep 3
else
echo "" >/tmp/.update_status
sleep 5000 # only do a recheck every 1.5 hours to save some cpu time
fi
done
module (add to ~/.config/polybar/modules.conf
)
[module/pkg]
type = custom/script
exec = tail -F /tmp/.update_status
exec-if = [ -p /tmp/.update_status ]
label-padding = 1
tail = true
setup
Once you’ve got the scripts and modules setup the scripts need to actually be started (as a background process with &
).
So two options:
- Install
archlabs-scripts
from the unstable repo, it looks for~/bin/check-network
and~/bin/check-update
and runs them if they are executable so you shouldn’t have to do anything but runal-polybar-session
. - Execute the scripts in your startup procedure. Because they just dump to a pipe they can be started whenever. Since startup varies I’ll just use basic shell syntax that can be used in
~/.xinitrc ~/.xprofile ~/.config/openbox/autostart ~/.config/bspwm/bspwmrc
but this can be translated to others easily.$HOME/bin/check-update & $HOME/bin/check-network &
Lemme know if you have any issues,
Cheers