You are not logged in.
Hello.
I created some "arch" shell scripts for polybar. It mimics i3pystatus updates module.
More at:
https://github.com/wioo/arch_polybar
Last edited by wioo (2018-01-14 12:22:30)
Offline
You have some very odd conditionals in those scripts.
First you have a conditional that does the same thing on both branches - there's not need for that. Also, your second conditional starting on line 28 of arch_update.sh repeats what was already done above, but instead of appending to the file it completely overwrites the file if there are any aur updates (so if there are any aur updates, no repo updates will be shown).
Second, there is no reason to echo "" to dev null! It seems you do that just so that you can use the esle clause: you can just change the condition of the test in the first place to "-gt 0" rather than testing whether it equals zero and doing nothing if it does and something in the else clause.
There's also no need to pipe awk to `nl` as awk can add line numbers. I suspect this would be cleaner with printf rather than print in awk, but I'm not familiar with trizen's output to test (sed might be even cleaner).
Far more importantly, though, the `checkupdates` and `trizen` commands are by far the most resource intensive parts of the script, and you needlessly repeat them 2 to 3 times each to regenerate the exact same output. Generate the output once, then do what you need with it as needed.
And most importantly, you run a loop, but you get the number of updates only when the script first starts! So if there no updates when the script first starts, it will continue to report 0 updates indefeinitely, even when there are new updates. The checkupdates and trizen commands should be run once each time through the loop.
The following does the same thing and fixes all the above:
#!/bin/sh
path=${HOME}/.config/polybar/scripts/arch/
while true; do
checkupdates | nl -w2 -s '. ' >| ${path}repo.pkgs
trizen -Su --aur --quiet | awk '{print NR ". " substr($2, 1, length($2) - 1) " " $3 " -> " $5}' >| ${path}aur.pkgs
updates=$(cat ${path}*.pkgs | wc -l)
echo "0" >| ${path}status
[ $updates -gt 0 ] && echo "%{F3e60053}$updates" >| ${path}status
>| ${path}packages
[ -s ${path}repo.pkgs ] && cat ${path}repo.pkgs >> ${path}packages
[ -s ${path}aur.pkgs ] && (printf "\nAUR updates\n"; cat ${path}aur.pkgs) >> ${path}packages
sleep 600
done
I'd still like to see the awk line cleaned up, but without knowing what trizen output is like that is hard to test.
Last edited by Trilby (2018-01-14 13:18:23)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Wow, thanks for your suggestions.
Output of trizen is
1. trizen: 1:1.37-1 ==> 1:1.39-1
and I like it to be
1. trizen 1:1.37-1 -> 1:1.39-1
also if there are aur updates and no repo updates "AUR updates" should not be printed in new line.
Offline
If trizen really prints the line number like that, then the whole awk script can be replaced with `sed 's/://;s/==/-/`:
#!/bin/sh
path=${HOME}/.config/polybar/scripts/arch/
while true; do
checkupdates | nl -w2 -s '. ' >| ${path}repo.pkgs
trizen -Su --aur --quiet | sed 's/://;s/==/-/' >| ${path}aur.pkgs
updates=$(cat ${path}*.pkgs | wc -l)
echo "0" >| ${path}status
[ $updates -gt 0 ] && echo "%{F3e60053}$updates" >| ${path}status
>| ${path}packages
[ -s ${path}repo.pkgs ] && cat ${path}repo.pkgs >> ${path}packages
[ -s ${path}repo.pks ] && [ -s ${path}aur.pkgs ] && printf "\n" >> ${path}packages
[ -s ${path}aur.pkgs ] && sed '1iAUR Updates' ${path}aur.pkgs >> ${path}packages
sleep 600
done
Last edited by Trilby (2018-01-14 14:25:38)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thank you.
Offline