summaryrefslogtreecommitdiff
path: root/common/home/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'common/home/scripts')
-rw-r--r--common/home/scripts/loadconfig59
1 files changed, 49 insertions, 10 deletions
diff --git a/common/home/scripts/loadconfig b/common/home/scripts/loadconfig
index 9f3fe57..f355092 100644
--- a/common/home/scripts/loadconfig
+++ b/common/home/scripts/loadconfig
@@ -1,15 +1,54 @@
#!/bin/sh
-cmd=$(printf "test\nswitch" | wofi -d -p 'Loading Type')
+CONFIG_PATH=$HOME/global/system/config/
-[ -z "$cmd" ] && exit
+NID=$RANDOM
-echo CMD = $cmd
+cmd=$(printf "Test\nSwitch\nCommit\nUpdate" | wofi -d -p 'Select')
-alacritty --class Hyprland::WinClass::Floating -e sh -c "
-sudo nixos-rebuild $cmd --flake '$HOME/global/system/config/'
-echo
-echo Press [Return] to continue
-echo
-read
-"
+kind=test
+desc=Temporarily
+
+case "$cmd" in
+
+ Update)
+ nix flake update --flake "$CONFIG_PATH"
+ dunstify " NixOS - Config" "Updated Flake"
+ ;;&
+
+ Switch | Commit | Update)
+ git -C "$CONFIG_PATH" add .
+ git -C "$CONFIG_PATH" commit -m "$(date '+%Y-%m-%d updates by auto-switch')"
+ dunstify " NixOS - Config" "Created New Commit"
+
+ case "$cmd" in
+ Commit | Update) exit;
+ esac
+
+ kind=switch
+ desc=Permanently
+ ;;&
+
+ Test | Switch)
+ dunstify -r "$NID" " NixOS - Config" "Switching Config $desc." --hints=int:value:0 -t 0
+
+ declare -i i=0
+
+ sudo nixos-rebuild "$kind" --flake "$CONFIG_PATH" 2>&1 | while read line; do
+ case "$line" in
+ these*)n=$(echo "$line" | grep -Eo '[0-9]*');;
+ "building '"*)
+ i+=1
+ progress=$(($i * 100 / $n))
+ dunstify -r "$NID" " NixOS - Config" "Switching Config $desc." --hints=int:value:"$progress" -t 0
+ ;;
+ *error*)
+ dunstify -r "$NID" -u 2 " NixOS - Config" "Error Loading Config"
+ ;;
+ Done.)
+ dunstify -r "$NID" " NixOS - Config" "Switching Config $desc.\nDone."
+ ;;
+ esac
+ done
+ ;;
+esac