From 66237480c2805d14dbff03a86408db371f1660a8 Mon Sep 17 00:00:00 2001 From: Peritia Date: Tue, 15 Jul 2025 11:41:06 +0200 Subject: [PATCH] fix github repo --- zsh/nyx-cleanup.zsh | 106 +++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/zsh/nyx-cleanup.zsh b/zsh/nyx-cleanup.zsh index 8bd93b6..fc8d709 100644 --- a/zsh/nyx-cleanup.zsh +++ b/zsh/nyx-cleanup.zsh @@ -1,73 +1,87 @@ +# nyx-cleanup.zsh โ€” Improved Version + function nyx-cleanup() { - - ###### CONFIGURATION ###### - local version="1.0.0" + ##### ๐Ÿ› ๏ธ CONFIGURATION ##### + local version="1.3.0" local keep_generations="${keep_generations:-5}" + local start_human=$(date '+%Y-%m-%d %H:%M:%S') + local nix_cleanup_log="nixos-cleanup.log" + local optimize_store="${optimize_store:-false}" + local auto_push="${auto_push:-false}" - # Setup 16-color ANSI (TTY-safe) - if [[ -t 1 ]]; then - RED=$'\e[31m'; GREEN=$'\e[32m'; YELLOW=$'\e[33m'; BLUE=$'\e[34m' - MAGENTA=$'\e[35m'; CYAN=$'\e[36m'; BOLD=$'\e[1m'; RESET=$'\e[0m' - else - RED=""; GREEN=""; YELLOW=""; BLUE="" - MAGENTA=""; CYAN=""; BOLD=""; RESET="" - fi + local RED=$'\e[31m'; local GREEN=$'\e[32m'; local YELLOW=$'\e[33m' + local BLUE=$'\e[34m'; local MAGENTA=$'\e[35m'; local CYAN=$'\e[36m' + local BOLD=$'\e[1m'; local RESET=$'\e[0m' - print_line() { echo -e "${BOLD}$(printf '%*s\n' "${COLUMNS:-40}" '' | tr ' ' '=')${RESET}"; } + ##### ๐Ÿ“ PATH SETUP ##### + local timestamp=$(date '+%Y-%m-%d_%H-%M-%S') + local hostname_id=$(hostname) + local log_dir="$nix_dir/Misc/nyx/logs/$hostname_id" + mkdir -p "$log_dir" + local cleanup_log="$log_dir/cleanup-$timestamp.log" + local log_file="$log_dir/nixos-gen-cleanup-$timestamp.log" + ##### ๐Ÿงฐ HELPERS ##### + console-log() { + echo -e "$@" | tee -a "$cleanup_log" + } + + print_line() { + console-log "${BOLD}$(printf '%*s\n' "${COLUMNS:-40}" '' | tr ' ' '=')${RESET}" + } + + ##### ๐Ÿ“˜ TOOL INFO ##### print_line - echo -e "${BOLD}${CYAN}๐Ÿงผ Nyx Cleanup v${version}${RESET}" + nix-tool "Nyx" "nyx-cleanup" "$version" \ + "Smart NixOS configuration cleanup" \ + "by Peritia-System" \ + "https://github.com/Peritia-System/Nyx-Tools" \ + "https://github.com/Peritia-System/Nyx-Tools/issues" \ + "Always up to date for you!" + echo + echo -e "${BOLD}${CYAN}๐Ÿงผ Nyx Cleanup v$version${RESET}" print_line - ###### TOOL DESCRIPTION ###### - echo -e "${MAGENTA}Cleaning up old generations and Nix garbage...${RESET}" - echo "Started cleanup: $(date)" | tee nixos-cleanup.log + ##### ๐Ÿงน EXECUTION ##### + console-log "${MAGENTA}Cleaning up old generations and Nix garbage...${RESET}" + console-log "Started cleanup: $(date)" - ###### GARBAGE COLLECTION ###### - echo -e "\n${BLUE}๐Ÿ—‘๏ธ Running Nix garbage collection...${RESET}" | tee -a nixos-cleanup.log - sudo nix-collect-garbage -d | tee -a nixos-cleanup.log + console-log "\n${BLUE}๐Ÿ—‘๏ธ Running Nix garbage collection...${RESET}" + sudo nix-collect-garbage -d | tee -a "$nix_cleanup_log" - ###### REMOVE OLD GENERATIONS ###### - echo -e "\n${BLUE}๐Ÿงน Removing old generations (keeping last ${keep_generations})...${RESET}" | tee -a nixos-cleanup.log - sudo nix-collect-garbage --delete-older-than "${keep_generations}d" | tee -a nixos-cleanup.log + console-log "\n${BLUE}๐Ÿงน Removing old generations (keeping last $keep_generations)...${RESET}" + sudo nix-collect-garbage --delete-older-than "${keep_generations}d" | tee -a "$nix_cleanup_log" - ###### OPTIONAL STORE OPTIMIZATION ###### - if [[ "${optimize_store}" == "true" ]]; then - echo -e "\n${MAGENTA}๐Ÿ”ง Optimizing the Nix store...${RESET}" | tee -a nixos-cleanup.log - sudo nix-store --optimize | tee -a nixos-cleanup.log + if [[ "$optimize_store" == "true" ]]; then + console-log "\n${MAGENTA}๐Ÿ”ง Optimizing the Nix store...${RESET}" + sudo nix-store --optimize | tee -a "$nix_cleanup_log" fi - ###### SUCCESS SUMMARY ###### - print_line | tee -a nixos-cleanup.log - echo -e "${GREEN}${BOLD}โœ… Nix cleanup completed successfully!${RESET}" | tee -a nixos-cleanup.log - echo -e "${CYAN}๐Ÿ•’ Finished at: $(date)${RESET}" | tee -a nixos-cleanup.log - print_line | tee -a nixos-cleanup.log + ##### โœ… SUMMARY ##### + print_line + console-log "${GREEN}${BOLD}โœ… Nix cleanup completed successfully!${RESET}" + console-log "${CYAN}๐Ÿ•’ Finished at: $(date)${RESET}" + print_line - ###### OPTIONAL COMMIT LOG ###### - gen=$(nixos-rebuild list-generations | grep True | awk '{$1=$1};1') - gen_nmbr=$(nixos-rebuild list-generations | grep True | awk '{$1=$1};1' | awk '{printf "%04d\n", $1}') + ##### ๐Ÿ“ GIT LOGGING ##### + local gen_nmbr=$(nixos-rebuild list-generations | grep True | awk '{print $1}' | tail -1 | xargs printf "%04d\n") cd "$nix_dir" || return 1 - local log_dir="$nix_dir/Misc/nyx/logs/$(hostname)" - mkdir -p "$log_dir" - local timestamp=$(date '+%Y-%m-%d_%H-%M-%S') - local log_file="$log_dir/nixos-gen_$gen_nmbr-cleanup-$timestamp.log" - - mv nixos-cleanup.log "$log_file" + mv "$nix_cleanup_log" "$log_file" git add "$log_file" if ! git diff --cached --quiet; then git commit -m "Cleanup log on $timestamp" - echo -e "${GREEN}โœ… Cleanup log committed.${RESET}" + console-log "${GREEN}โœ… Cleanup log committed.${RESET}" else - echo -e "${YELLOW}โ„น๏ธ No new changes in logs to commit.${RESET}" + console-log "${YELLOW}โ„น๏ธ No new changes in logs to commit.${RESET}" fi - if [[ "${auto_push}" == "true" ]]; then - echo -e "${BLUE}๐Ÿš€ Auto-push enabled. Pushing to remote...${RESET}" - git push && echo -e "${GREEN}โœ… Changes pushed to remote.${RESET}" + if [[ "$auto_push" == "true" ]]; then + console-log "${BLUE}๐Ÿš€ Auto-push enabled. Pushing to remote...${RESET}" + git push && console-log "${GREEN}โœ… Changes pushed to remote.${RESET}" fi - echo -e "\n${GREEN}๐ŸŽ‰ Nyx cleanup finished!${RESET}" + console-log "\n${GREEN}๐ŸŽ‰ Nyx cleanup finished!${RESET}" print_line }