From a22331dcaa00d89ce8d7393925df47555621ee1b Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L. de Mello" Date: Wed, 10 Apr 2024 13:03:59 -0300 Subject: [PATCH] refactor: move formatting to util function --- modules/nixos/programs/nih/cli.sh | 47 +++++++++++++------------------ 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/modules/nixos/programs/nih/cli.sh b/modules/nixos/programs/nih/cli.sh index 70a8d3b..78c5ab2 100644 --- a/modules/nixos/programs/nih/cli.sh +++ b/modules/nixos/programs/nih/cli.sh @@ -55,6 +55,23 @@ function util-build() { popd } +function util-format() { + local prefix="$1" + local flake_dir="$2" + + pushd $flake_dir + + gum log --structured --prefix "$prefix" --level debug 'Formatting files' + alejandra . &>/dev/null \ + || (alejandra . ; \ + gum log --structured \ + --prefix "$prefix" \ + --level error 'Failed to format files' \ + && exit 1) + + popd +} + function nih-edit() { local flake_dir="$1" local host="$2" @@ -78,14 +95,7 @@ function nih-edit() { exit 0 fi - # Autoformat nix files - gum log --structured --prefix 'nih edit' --level debug 'Formatting files' - alejandra . &>/dev/null \ - || (alejandra . ; \ - gum log --structured \ - --prefix 'nih edit' \ - --level error 'Failed to format files' \ - && exit 1) + util-format 'nih edit' $flake_dir # Show modifications util-show-diff 'nih edit' @@ -142,13 +152,7 @@ function nih-switch () { gum log --structured --prefix 'nih switch' --level info 'Switching NixOS config' - gum log --structured --prefix 'nih switch' --level debug 'Formatting files' - alejandra . &>/dev/null \ - || (alejandra . ; \ - gum log --structured \ - --prefix 'nih switch' \ - --level error 'Failed to format files' \ - && exit 1) + util-format 'nih switch' $flake_dir # Build nixos util-build 'nih switch' $flake_dir $host @@ -158,11 +162,6 @@ function nih-switch () { --icon=software-update-available \ --urgency=low - gum log --structured --prefix 'nih edit' --level info 'NixOS rebuilt!' - notify-send -e "NixOS Rebuilt!" \ - --icon=software-update-available \ - --urgency=low - popd } @@ -203,13 +202,7 @@ function nih-sync() { gum log --structured --prefix 'nih sync' --level info 'Syncing NixOS config' - gum log --structured --prefix 'nih sync' --level debug 'Formatting files' - alejandra . &>/dev/null \ - || (alejandra . ; \ - gum log --structured \ - --prefix 'nih sync' \ - --level error 'Failed to format files' \ - && exit 1) + util-format 'nih sync' $flake_dir git reset ./secrets/*.decrypted.* for f in ./secrets/*.decrypted.*; do