Push/Pull + Formatting

This commit is contained in:
Marta 2025-06-08 02:39:51 +02:00
parent acf18ad3ba
commit 8ab2eb9b93

53
nixie
View file

@ -1,11 +1,9 @@
#!/usr/bin/env bash
NC='\033[0m' # No Colour
Red='\033[0;31m' # Red
Yellow='\033[0;33m' # Yellow
Purple='\033[0;35m' # Purple
IRed='\033[0;91m' # Red
IYellow='\033[0;93m' # Yellow
IPurple='\033[0;95m' # Purple
NC='\033[0m'
Red='\033[1;31m'
Yellow='\033[1;33m'
Purple='\033[0;35m'
IPurple='\033[0;95m'
QUIT () {
popd > /dev/null
@ -18,7 +16,7 @@ QUIT1 () {
}
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}"
read CHOICE
case $CHOICE in
@ -27,27 +25,43 @@ CHOOSE_CASE () {
[eE]* ) EDIT ;;
[rR]* ) RESTORE ;;
[qQ]* ) echo -e "${IPurple}Quitting nixie. ${Purple}Changes kept in /etc/nixos.${NC}" && QUIT ;;
*) echo -e -n "[ ${Red}incorrect input${NC} ] " && CHOOSE_CASE ;;
*) echo -e -n "[ ${Red}incorrect input ${NC}] " && CHOOSE_CASE ;;
esac
}
BUILD () {
echo -e "${IPurple}This will rebuild NixOS, and if there are no errors, commit changes to git."
echo -e -n "${IPurple}Are you sure you want to do this? ${Purple}(Y/n):${NC} "
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 "[ ${Red}cancelled${NC} ] " && CHOOSE_CASE ;;
[nN]* ) echo -e -n "[ ${Red}cancelled ${NC}] " && CHOOSE_CASE ;;
*)
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}"
echo -e "[ ${Red}error ${NC}] ${Red}Rebuilding NixOS failed.${NC}"
QUIT1
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. Quitting nixie.${NC}"
echo -e "${IPurple}System rebuilt, configuration commited.${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}" ;;
*)
echo -e "${IPurple}Squashing...${NC}"
sudo git rebase origin/HEAD
echo -e "${IPurple}Pushing...${NC}"
sudo git push
;;
esac
echo -e "${IPurple}Quitting nixie.${NC}"
QUIT
;;
esac
@ -59,25 +73,30 @@ PREVIEW () {
}
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? (y/N):${NC} "
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 "[ ${Red}cancelled${NC} ] " && CHOOSE_CASE ;;
*) echo -e -n "[ ${Red}cancelled ${NC}] " && CHOOSE_CASE ;;
esac
}
# Script
pushd /etc/nixos > /dev/null
echo -e "${IPurple}Running pixie. You might be asked to input the root password.${NC}"
echo -e "${IPurple}Running pixie. ${Purple}You might be asked to input the root password.${NC}"
sudo echo -n
echo -e "${IPurple}Pulling from origin...${NC}"
sudo git pull
EDIT
QUIT