Error handling ig

This commit is contained in:
Marta 2025-06-07 23:16:17 +02:00
parent 4718468fdb
commit acf18ad3ba

11
nixie
View file

@ -12,6 +12,11 @@ QUIT () {
exit exit
} }
QUIT1 () {
popd > /dev/null
exit 1
}
CHOOSE_CASE () { CHOOSE_CASE () {
echo -e -n "${IPurple}Build changes? ${Purple}Yes/Preview/Edit/Restore/Quit. (y/p/e/r/q):${NC} " echo -e -n "${IPurple}Build changes? ${Purple}Yes/Preview/Edit/Restore/Quit. (y/p/e/r/q):${NC} "
@ -33,12 +38,12 @@ BUILD () {
case $CHOICE in case $CHOICE in
[nN]* ) echo -e -n "[ ${Red}cancelled${NC} ] " && CHOOSE_CASE ;; [nN]* ) echo -e -n "[ ${Red}cancelled${NC} ] " && CHOOSE_CASE ;;
*) *)
git add . sudo git add .
echo -e "${IPurple}Rebuilding NixOS...${NC}" echo -e "${IPurple}Rebuilding NixOS...${NC}"
sudo nixos-rebuild switch sudo nixos-rebuild switch
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "[ ${Bred}error${NC} ] ${Red}Rebuilding NixOS failed.${NC}" echo -e "[ ${Red}error${NC} ] ${Red}Rebuilding NixOS failed.${NC}"
QUIT QUIT1
fi fi
echo -e "${IPurple}Committing the changes...${NC}" echo -e "${IPurple}Committing the changes...${NC}"
sudo git commit --no-status -am "$(sudo nixos-rebuild list-generations | grep current | sed 's/ .*//')" sudo git commit --no-status -am "$(sudo nixos-rebuild list-generations | grep current | sed 's/ .*//')"