1
1
mirror of https://github.com/nboughton/dotfiles synced 2024-11-22 23:51:57 +01:00

do pacman update check in go

This commit is contained in:
Nick Boughton 2020-12-08 11:37:20 +00:00
parent 6501b08304
commit 2f3c8910b9
5 changed files with 64 additions and 16 deletions

@ -6,6 +6,6 @@ text-color=#d8dee9
border-color=#434c5e
border-radius=7
max-icon-size=32
default-timeout=0
default-timeout=30000
anchor=top-right
margin=20

@ -122,7 +122,7 @@
"format": " {}",
"return-type": "json",
"interval": 3600, // every 30 minutes
"exec": "~/.config/waybar/modules/update-check.sh",
"exec": "go run ~/.config/waybar/modules/update-check.go",
"exec-if": "exit 0",
"on-click": "~/.config/waybar/modules/update-system.sh; pkill -RTMIN+8 waybar", // update system
"signal": 8,

@ -0,0 +1,60 @@
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"strings"
)
type jsonOutput struct {
Text string `json:"text,omitempty"`
Alt string `json:"alt,omitempty"`
Tooltip string `json:"tooltip,omitempty"`
Class string `json:"class,omitempty"`
Percentage int `json:"percentage,omitempty"`
}
func main() {
pac, err := exec.Command("checkupdates").CombinedOutput()
if err != nil {
log.Fatal("could not get pacman updates: ", string(pac))
}
aur, err := exec.Command("yay", "--devel", "-Qu").CombinedOutput()
if err != nil {
log.Fatal("could not get aur updates: ", string(aur))
}
updates := []string{}
for _, line := range strings.Split(string(pac), "\n") {
if len(line) > 0 {
updates = append(updates, line)
}
}
for _, line := range strings.Split(string(aur), "\n") {
if len(line) > 0 {
updates = append(updates, line)
}
}
n := len(updates)
class := "no-updates"
if n > 0 {
class = "updates"
}
o := jsonOutput{
Text: fmt.Sprintf("%d", n),
Alt: fmt.Sprintf("%d", n),
Tooltip: strings.Join(updates, "\n"),
Class: class,
Percentage: n,
}
json.NewEncoder(os.Stdout).Encode(o)
}

@ -1,14 +0,0 @@
#!/bin/bash
aur_updates=$(yay --devel -Qqmu)
pac_updates=$(checkupdates | awk '{print $1}')
text=$(printf "${aur_updates}${pac_updates}" | wc -l)
alt=$text
tooltip=$(printf "${pac_updates}${aur_updates}" | sed ':a;N;$!ba;s/\n/\\n/g')
percentage=$text
class="no-updates"
if [[ $text -gt 0 ]]; then
class="updates"
fi
echo "{\"text\": \"$text\", \"alt\": \"$alt\", \"tooltip\": \"$tooltip\", \"class\": \"$class\", \"percentage\": $percentage }"

@ -66,9 +66,11 @@ window#waybar {
border-bottom-right-radius: 7px;
}
/*
#tray {
background: rgba(76, 86, 106, 0.75);
}
*/
#custom-pacman.no-updates {
background: rgba(163, 190, 140, 0.75);