Push/Pull + Formatting

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

43
nixie
View file

@ -1,11 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
NC='\033[0m' # No Colour NC='\033[0m'
Red='\033[0;31m' # Red Red='\033[1;31m'
Yellow='\033[0;33m' # Yellow Yellow='\033[1;33m'
Purple='\033[0;35m' # Purple Purple='\033[0;35m'
IRed='\033[0;91m' # Red IPurple='\033[0;95m'
IYellow='\033[0;93m' # Yellow
IPurple='\033[0;95m' # Purple
QUIT () { QUIT () {
popd > /dev/null popd > /dev/null
@ -18,7 +16,7 @@ QUIT1 () {
} }
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}"
read CHOICE read CHOICE
case $CHOICE in case $CHOICE in
@ -33,7 +31,7 @@ CHOOSE_CASE () {
BUILD () { BUILD () {
echo -e "${IPurple}This will rebuild NixOS, and if there are no errors, commit changes to git." 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 read CHOICE
case $CHOICE in case $CHOICE in
[nN]* ) echo -e -n "[ ${Red}cancelled ${NC}] " && CHOOSE_CASE ;; [nN]* ) echo -e -n "[ ${Red}cancelled ${NC}] " && CHOOSE_CASE ;;
@ -47,7 +45,23 @@ BUILD () {
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/ .*//')"
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 QUIT
;; ;;
esac esac
@ -59,6 +73,7 @@ PREVIEW () {
} }
EDIT () { EDIT () {
echo -e "${IPurple}Opening editor...${NC}"
sudo vim . sudo vim .
sudo git diff --stat sudo git diff --stat
CHOOSE_CASE CHOOSE_CASE
@ -66,7 +81,7 @@ EDIT () {
RESTORE () { RESTORE () {
echo -e "[ ${Yellow}Warning ${NC}] ${Purple}This will restore /etc/nixos to the last commit.${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? (y/N):${NC} " echo -e -n "[ ${Yellow}Warning ${NC}] ${Purple}Are you sure you want to disregard the changes? Yes/No (y/N): ${NC}"
read CHOICE read CHOICE
case $CHOICE in case $CHOICE in
[yY]* ) sudo -k git restore . && echo -e "${IPurple}Quitting nixie. ${Purple}Changes disregarded.${NC}" && QUIT ;; [yY]* ) sudo -k git restore . && echo -e "${IPurple}Quitting nixie. ${Purple}Changes disregarded.${NC}" && QUIT ;;
@ -77,7 +92,11 @@ RESTORE () {
# Script # Script
pushd /etc/nixos > /dev/null 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 EDIT
QUIT QUIT