From bfb9806460b933b04596d07b4afe2fb1d0f68259 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Fri, 30 Oct 2026 11:45:35 +0100 Subject: [PATCH] fix template uninstall : add missing skeleton_tests.hpp and check the symlink target instead of the key phrase Generated by Mistral Vibe. --- uninstall.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 192d9e4..f902b47 100644 --- a/uninstall.sh +++ b/uninstall.sh @@ -4,6 +4,7 @@ source ./asides/color.sh KEY_PHRASE="#hugogogo#" +HERE=$(pwd) # receive 1 argument : absolute path to config file function restore_bak @@ -71,15 +72,58 @@ function uninstall echo # Add a blank line for readability } +# receive 1 argument : absolute path to a template file +# same as uninstall(), but for template files (the skeletons) : +# they can't contain the key phrase, it would pollute every generated +# file. so this one checks that the symlink points into this +# repository instead, like install.sh does to find the right file +function uninstall_template +{ + local file_to="$1" + local file_name="$(basename "$1")" + local path_file_to="$(dirname "$1")" + + echo -e $B_BLUE"--- Uninstalling template \"$file_name\" ---"$ENDCO + + # -L check if is symlink + if [ -L "$file_to" ] + then + echo -e $YELLOW"Found symlink: $file_to"$ENDCO + local target_file=$(readlink "$file_to") + if [ "$(realpath -m "$target_file")" = "$HERE/config_files/$file_name" ] + then + echo -e $GREEN"Symlink points to this repository. This is one of our template files."$ENDCO + echo -en $YELLOW"in " + echo -en $CYAN"\"$path_file_to/\"" + echo -en $YELLOW", rm symlink " + echo -en $CYAN"\"$file_name\""$ENDCO"\n" + rm "$file_to" + + if [ -f "$file_to.hubak0" ] + then + restore_bak "$file_to" + else + echo -e $YELLOW"No backup file found to restore."$ENDCO + fi + else + echo -e $RED"Symlink does not point to this repository. Skipping to avoid removing a file not managed by this script."$ENDCO + fi + else + echo -e $YELLOW"Not a symlink, or does not exist. Skipping: $file_to"$ENDCO + fi + echo # Add a blank line for readability +} + # argument : directory where the config file should go echo -e $B_MAGENTA"--- Starting uninstall process ---"$ENDCO"\n" uninstall "$HOME/.screenrc" uninstall "$HOME/.vimrc" uninstall "$HOME/.zshrc" -uninstall "$HOME/.vim/templates/skeleton_colors.h" -uninstall "$HOME/.vim/templates/skeleton.cpp" -uninstall "$HOME/.vim/templates/skeleton.hpp" -uninstall "$HOME/.vim/templates/skeleton_main.cpp" -uninstall "$HOME/.vim/templates/skeleton_makefile" -uninstall "$HOME/.vim/templates/skeleton.html" +uninstall_template "$HOME/.vim/templates/skeleton_colors.h" +uninstall_template "$HOME/.vim/templates/skeleton_tests.hpp" +uninstall_template "$HOME/.vim/templates/skeleton.cpp" +uninstall_template "$HOME/.vim/templates/skeleton.hpp" +uninstall_template "$HOME/.vim/templates/skeleton_main.cpp" +uninstall_template "$HOME/.vim/templates/skeleton_makefile" +uninstall_template "$HOME/.vim/templates/skeleton.html"