Anachron / i3blocks

Additional/custom blocks which fit my needs
GNU General Public License v3.0
583 stars 106 forks source link

Package updates Blocklet counting error (off by one more) #23

Closed diffficult closed 4 years ago

diffficult commented 8 years ago

Checked a previous closed issue that made the blocklet return one more package than it supposed to. In my case the package blocklet reads " 1" when $ pacman -Qu | wc -l actually returns "0". Don't know if it has to do with changes on pacman, but undoing the changes to the last commit to the packages script makes the blocklet to not display anything at all.

Anachron commented 8 years ago

Well that's weird. Why do some people experience this issue when before my fix and why others experience it after? Which version of pacman are you using?

diffficult commented 8 years ago

Running 'Pacman v5.0.1 - libalpm v10.0.1' on Antergos. Yes, I thought it was weird too after I checked the previous closed issue and the modification you did to the script. Other than that it's running fine. I made a small modification and also added

case $BLOCK_BUTTON in
    #2) pamac-manager  # middle click
    3) pamac-updater  # right click - opens pamac-updater
esac

at the end to open pamac-updater and wanted to get pamac-manager with middle click but for some reason middle click doesn't launch anything.

diffficult commented 8 years ago

I made a modification to your script. I'm new to all this and was testing it yesterday after I posted. I used your script as base and read a little about to try to write a proper script.

What I got was this

#!/usr/bin/bash

PACKAGES=$(pacman -Qu | wc -l)
URGENT_VALUE=25

if [[ $PACKAGES -gt 0 && $PACKAGES -gt $URGENT_VALUE ]]; then
    echo '<span foreground="#FF0000">'"$PACKAGES"'</span>' # full-text
    echo '<span foreground="#FF0000">'"[$PACKAGES]"'</span>' # short-text
elif [[ $PACKAGES -gt 0 ]]; then
    echo '<span foreground="#FFAE00">'"$PACKAGES"'</span>' # full-text
    echo '<span foreground="#FFAE00">'"[$PACKAGES]"'</span>' # short-text
elif [[ $PACKAGES -eq 0 ]]; then
    echo '<span foreground="#A8FF00">'""'</span>' #full-text
    echo '<span foreground="#A8FF00">'""'</span>' #short-text 
fi

#---------i3blocks actions-----------------------------------------------

case $BLOCK_BUTTON in
    2) pamac-manager ;; # middle click
    3) pamac-updater ;; # right click - opens pamac-updater
esac

It will check for the amount of packages you can update and if it is =0 will display a green check mark (taken from FontAwesome) next to the label set in the i3blcoks.conf or just a green checkbox for the short text version. I used the URGENT_VALUE to tell it to make the package count be displayed in red or orange when it is greater than 0.

I fixed the actions, was missing ;; at the end of each case line (newbe mistake), so now you call pamac-manager with middle click and pamac-updater with left click to see the list of packages you can update and make the update.

Most probably I broke how you made this work with your notifier script, I have yet still to test it and adapt it to some of the blocklets I'm actually running.

Hope this helps and I'm sorry for the inconvenience and writing this long post, still learning how to do things around with git and how to properly push a new file or change for revision into a project. Thanks for keeping this repo updated and checking for issues.

vKnmnn commented 7 years ago

there is a very convenient tool that's a lot easier and safer to use. it's called checkupdates and it's part of pacman! it returns a list of outdated packages, which should be a lot easier to parse.

vKnmnn commented 7 years ago

I wrote my own block for this, may this inspire you. it depends on rofi , but you could change that. It also gets one color which depends on wal but thats even easier to edit. It's the $white one.

#!/bin/bash

UPDATECOUNT=$( checkupdates | wc -l)
#load colors from wal
. /home/omicron/.cache/wal/colors.sh

markup(){
    red="#ff0000"
    green="#00ff00"
    white="${foreground}"
    close="</span>"
    #make an array of checkupdates output lines
    mapfile -t updates < <(checkupdates)

    for line in "${updates[@]}";
        do 
                 echo "$line" | awk -F " " '{ print $1 "<span color=\"'$red'\"> "$2"'$close'<span color=\"'$white'\"> "$3"'$close'<span color=\"'$green'\"> "$4"'$close'" }'
        done
}

show_updates(){
if [ "$UPDATECOUNT" == 0 ] ; then 
    echo "0"
    exit 0
    pkill -RTMIN+3 i3blocks
elif
    [ "$UPDATECOUNT" -gt 20 ] ; then
    line_num=20
else
    line_num="$UPDATECOUNT"
fi
    markup \
        | sed 's/^/ /' \
        | rofi -no-fullscreen -width -50 -bw 2 -m -3 -theme-str '#window {anchor:southeast;}' -eh 1 -font 'Monospace 6' -dmenu -p "Available updates" -markup-rows -lines "${line_num}"  > /dev/null
    echo "$UPDATECOUNT"
    echo "$UPDATECOUNT"
    pkill -RTMIN+3 i3blocks
    exit 0

}

case $BLOCK_BUTTON in
    3) gksu -k 'xfce4-terminal -x aura -Syu --noconfirm'
        ;;
    1|2) show_updates
        exit 0
        ;;
esac
    echo "$UPDATECOUNT"
    echo "$UPDATECOUNT"