You are not logged in.

#1 2013-08-08 17:47:46

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Best way to use `checkupdates' for status line

Hey there,

I want to have the number of packages for which there exist updates to be indicated in the status bar of dwm. (At the moment I create my status bar via a shell script, not via a C program. Most importantly the script displays at the moment the number of new emails and the date/time.)

This was my first attempt (other functions and custom colors stripped):

#!/bin/bash
pkg(){
    nbr="$(checkupdates | wc -l)"
    echo -en "$nbr"
}

xsetroot -name "... $(pkg) | $(date "+%d. %b %H:%M")"

After the script has been executed it will be launched again after a sleep of two seconds. Now I wonder if it is considered good practice to execute `checkupdates' every few seconds. I guess it is not. What could be the downsides? Problems when invoking pacman in order to update?

The other way I thought of was to check for updates only every hour via cron and redirecting the number of package updates into a temporary file and reading that file in the status script. But this has a major downside: After updating with pacman, the number of packages to be updated doesn't change until next invocation of the cronjob...

How would you handle such a notification?

Edit: Sorry wrong forum. Please move the topic. :-(

Last edited by ball (2013-08-08 17:48:55)

Offline

#2 2013-08-08 17:58:18

HalosGhost
Member
From: Twin Cities, MN
Registered: 2012-06-22
Posts: 1,486
Website

Re: Best way to use `checkupdates' for status line

Well, you could simplify that code a lot.

pkg="$(checkupdates|wc -l)"
xsetroot -name "... $pkg | $(date "+%d. %b %H:%M")"

Personally, my statusbar is run with a C program I put together. Having said that, I would probably use something very similar.

All the best,

-HG

Last edited by HalosGhost (2013-08-08 17:58:51)


"All errors are ᴘᴇʙᴋᴀᴄ errors—It's just a matter of narrowing down which keyboard and chair." -Trilby
\ldots

Offline

#3 2013-08-08 18:14:58

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,581
Website

Re: Best way to use `checkupdates' for status line

The other way I thought of was to check for updates only every hour via cron and redirecting the number of package updates into a temporary file and reading that file in the status script. But this has a major downside: After updating with pacman, the number of packages to be updated doesn't change until next invocation of the cronjob...

This is fine. It's not like you need to be notified of updates in <60min smile

That's what I do for AUR and aurphans. For checkupdates, I just hammer it...


Moving to Programming and Scripting...


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Online

#4 2013-08-08 18:21:42

Trilby
Forum Moderator
From: Massachusetts, USA
Registered: 2011-11-29
Posts: 13,706
Website

Re: Best way to use `checkupdates' for status line

#!/bin/bash

let loops=0
while true; do
   [[ $(($loops % 150)) -eq 0 ]] && pkg=$(checkupdates | wc -l)
   [[ $(($loops % 30)) -eq 0 ]] && email=...
   xsetroot -name "$pkg | $email"
   loops++
   sleep 2
done

This will run checkupdates every 150 times through the loop (every 5 minutes) and do the mail check every 30 (every minute), but print out the latest result from each every time through the loop.  Obviously, the mail part has to be filled in with whatever you use.  This is just to show how to only update at certain intervals rather than wasting processing on something that may not be that dynamic.

EDIT: for regular use I suppose their should be a check on "loops" to avoid overflow.  At the last line of the loop, for example, add

   [[ $loops -eq 4500 ]] && let loops=0

Last edited by Trilby (2013-08-08 18:24:58)


InterrobangSlider
• How's my coding? See this page.
• How's my moderating? Feel free to email any concerns, complaints, or objections.

Offline

#5 2013-08-09 07:34:39

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Re: Best way to use `checkupdates' for status line

Thanks for the pointers! I guess I'll start with Trilby's suggestions and then eventually move on to solution in C (if I find the time...)

Last edited by ball (2013-08-09 07:34:53)

Offline

Board footer

Powered by FluxBB