diff --git a/nixie b/nixie index 0c5ce90..569641e 100755 --- a/nixie +++ b/nixie @@ -10,18 +10,14 @@ QUIT () { exit } -QUIT1 () { - popd > /dev/null - exit 1 -} - CHOOSE_CASE () { - echo -e -n "${IPurple}What do you want to do? ${Purple}Edit/reBuild/reView/Restore/Quit (e/b/v/r/q): ${NC}" + echo -e -n "${IPurple}What do you want to do? ${Purple}Edit/reBuild/Update/reView/Restore/Quit (e/b/u/v/r/q): ${NC}" read CHOICE case $CHOICE in [eE]* ) EDIT ;; [bB]* ) BUILD ;; + [uU]* ) UPDATE ;; [vV]* ) REVIEW ;; [rR]* ) RESTORE ;; [qQ]* ) echo -e "${IPurple}Quitting nixie. ${Purple}Changes kept in /etc/nixos.${NC}" && QUIT ;; @@ -29,40 +25,61 @@ CHOOSE_CASE () { esac } +EDIT () { + echo -e "${IPurple}Opening editor...${NC}" + sudo vim . + sudo git diff --stat + CHOOSE_CASE +} + BUILD () { - echo -e "${IPurple}This will rebuild NixOS, and if there are no errors, commit changes to git." + echo -e "${IPurple}Continuing will rebuild NixOS and commit changes to git." echo -e -n "${IPurple}Are you sure you want to do this? ${Purple}Yes/No (Y/n): ${NC}" read CHOICE case $CHOICE in - [nN]* ) echo -e -n "[ ${Yellow}cancelled ${NC}] " && CHOOSE_CASE ;; + [nN]* ) echo -e -n "Cancelled " ;; *) sudo git add . echo -e "${IPurple}Rebuilding NixOS...${NC}" sudo nixos-rebuild switch if [ $? -ne 0 ]; then echo -e "[ ${Red}error ${NC}] ${Red}Rebuilding NixOS failed.${NC}" - QUIT1 + CHOOSE_CASE + QUIT fi echo -e "${IPurple}Committing the changes...${NC}" sudo git commit --no-status -am "$(sudo nixos-rebuild list-generations | grep current | sed 's/ .*//')" echo -e "${IPurple}System rebuilt, configuration commited.${NC}" - echo -e -n "${IPurple}Push changes? ${Purple}Yes/Squash/No (y/S/n): ${NC}" + echo -e -n "${IPurple}Push changes? ${Purple}Yes/Squash/No (y/s/N): ${NC}" read CHOICE case $CHOICE in [yY]* ) echo -e "${IPurple}Pushing...${NC}" sudo git push ;; - [nN]* ) echo -e -n "${IPurple}Not pushing changes. ${NC}" ;; - *) + [sS]* ) echo -e "${IPurple}Squashing...${NC}" sudo git rebase origin/HEAD echo -e "${IPurple}Pushing...${NC}" sudo git push ;; + *) echo -e -n "Not pushing changes. " ;; esac - echo -e "${IPurple}Quitting nixie.${NC}" - QUIT + ;; + esac + CHOOSE_CASE +} + +UPDATE () { + echo -e -n "${IPurple}Are you sure you want to update flake.lock? ${Purple}Yes/No (Y/n): ${NC}" + read CHOICE + case $CHOICE in + [nN]* ) echo -e -n "Cancelled " && CHOOSE_CASE ;; + *) + echo -e "${IPurple}Updating flake.lock..." + sudo nix flake update + echo -e -n "Updated. " + BUILD ;; esac } @@ -73,21 +90,18 @@ REVIEW () { CHOOSE_CASE } -EDIT () { - echo -e "${IPurple}Opening editor...${NC}" - sudo vim . - sudo git diff --stat - CHOOSE_CASE -} - RESTORE () { echo -e "[ ${Yellow}warning ${NC}] ${Purple}This will restore /etc/nixos to the last commit.${NC}" echo -e -n "[ ${Yellow}warning ${NC}] ${Purple}Are you sure you want to disregard the changes? Yes/No (y/N): ${NC}" read CHOICE case $CHOICE in - [yY]* ) sudo -k git restore . && echo -e "${IPurple}Quitting nixie. ${Purple}Changes disregarded.${NC}" && QUIT ;; - *) echo -e -n "[ ${Yellow}cancelled ${NC}] " && CHOOSE_CASE ;; + [yY]* ) + sudo -k git restore . + echo -e -n "Changes disregarded. " + ;; + *) echo -e -n "Cancelled. " ;; esac + CHOOSE_CASE } pushd /etc/nixos > /dev/null