From 59b19cb7127e6fe820e4fe8e110193b043dcdb57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 6 Jul 2024 13:09:47 +0200 Subject: [PATCH] Improve flakestat slightly --- home/hyprland/waybar/flakestat.sh | 43 ++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/home/hyprland/waybar/flakestat.sh b/home/hyprland/waybar/flakestat.sh index 175dd6c..1ffcb3c 100644 --- a/home/hyprland/waybar/flakestat.sh +++ b/home/hyprland/waybar/flakestat.sh @@ -1,5 +1,33 @@ #!/usr/bin/env bash +# Args: +# $1 text +# $2 tooltip +# $3 error-code +print_output() { + local text="$1" + local tooltip="$2" + local error_code="$3" + + if [ -z "$error_code" ]; then + output=$(jq -n \ + --arg text "$text" \ + --arg tooltip "$tooltip" \ + --unbuffered \ + --compact-output \ + '{text: $text, tooltip: $tooltip}') + else + output=$(jq -n \ + --arg text "$text" \ + --arg tooltip "$tooltip" \ + --unbuffered \ + --compact-output \ + '{text: $text, tooltip: $tooltip}') + fi + + echo "$output" +} + FLAKE_DIR="/home/torjus/nixos" NIXPKGS_DIR="/home/torjus/git/nixpkgs" @@ -9,18 +37,13 @@ unstable_input=$(echo "$flake_metadata" | jq '.locks.nodes.root.inputs.nixpkgs') unstable_rev=$(echo "$flake_metadata" | jq -r ".locks.nodes.$unstable_input.locked.rev") unstable_branch=$(echo "$flake_metadata" | jq -r ".locks.nodes.$unstable_input.original.ref") -cd "$NIXPKGS_DIR" || exit 1 +cd "$NIXPKGS_DIR" || print_output "?" "Could not find git repo dir" 1 git fetch -q --all -unstable_commit_count=$(git rev-list --count "$unstable_rev..origin/$unstable_branch") +if ! unstable_commit_count=$(git rev-list --count "$unstable_rev..origin/$unstable_branch"); then + print_output "?" "Unable to list commits" 1 +fi text="$unstable_commit_count" tooltip="${unstable_branch}: ${unstable_commit_count}" -output=$(jq -n \ - --arg text "$text" \ - --arg tooltip "$tooltip" \ - --unbuffered \ - --compact-output \ - '{text: $text, tooltip: $tooltip}') - -echo "$output" +print_output "$text" "$tooltip" 0