summaryrefslogtreecommitdiff
path: root/common/home/scripts/loadconfig
blob: f355092caafc3b51a7eff48b8e55e4f9bd3dc748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

CONFIG_PATH=$HOME/global/system/config/

NID=$RANDOM

cmd=$(printf "Test\nSwitch\nCommit\nUpdate" | wofi -d -p 'Select')

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