From 4b5426885c87d4675e49cae2b454ef9339b86440 Mon Sep 17 00:00:00 2001 From: William Date: Wed, 15 Oct 2025 20:02:47 -0300 Subject: [PATCH] added null check to hm-cli --- packages/hm-cli.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/hm-cli.nix b/packages/hm-cli.nix index ef3ec30..614f287 100644 --- a/packages/hm-cli.nix +++ b/packages/hm-cli.nix @@ -23,9 +23,9 @@ pkgs.writeShellScriptBin "hm" '' Environment Variables: HM_PATH Override default flake path (~/.config/home-manager) - Currently set to "$(echo $HM_PATH)" + Currently set to "''${HM_PATH:-}" HM_USER Override default user output ("$(whoami)@$(hostname)") - Currently set to "$(echo $HM_USER)" + Currently set to "''${HM_USER:-}" EOF } @@ -58,10 +58,14 @@ pkgs.writeShellScriptBin "hm" '' "$HM" remove-generations "$@" ;; rollback) - "$HM" generations | \ + PREV_GEN=$("$HM" generations | \ sed -n 's/^[[:space:]]*id \([0-9]\+\).*/\1/p' | \ - head -n 2 | tail -n 1 | \ - xargs -I {} "$HM" switch --flake "$FLAKE_PATH" --switch-generation {} + head -n 2 | tail -n 1) + if [[ -z "$PREV_GEN" ]]; then + echo "Error: could not determine previous generation (possibly only one generation exists)" + exit 1 + fi + "$HM" switch --flake "$FLAKE_PATH" --switch-generation "$PREV_GEN" ;; switch) if [[ $# -ne 3 ]]; then