From 579f675abcec894dfab5857468353da95810b128 Mon Sep 17 00:00:00 2001 From: H0mire Date: Wed, 22 May 2024 17:27:08 +0200 Subject: [PATCH 01/12] first steps for fixing and improving update-dots --- temp.txt | 0 update-dots.sh | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 temp.txt diff --git a/temp.txt b/temp.txt new file mode 100644 index 000000000..e69de29bb diff --git a/update-dots.sh b/update-dots.sh index ecc4225ab..7fbc0b854 100644 --- a/update-dots.sh +++ b/update-dots.sh @@ -44,7 +44,7 @@ cat << 'EOF' | | | This script will update your dotfiles (.config, .local, etc) by retrieving the latest version | | from the Git repository and then replacing the old config files with the updated ones. | -| To preserve your customizations, it will ask you if you wanna keep some modified | +| To preserve your customizations, it will ask you if you wanna keep some customized | | files untouched. | | | ################################################################################################### @@ -63,18 +63,18 @@ current_branch=$(git rev-parse --abbrev-ref HEAD) # fetch the latest version of the repository if ! git fetch; then - echo -e "${RED}Failed to fetch the latest version of the repository. Exiting.${RESET}" + echo -e "${RED}Failed to fetch the latest version of the repository. Exiting...${RESET}" exit 1 fi # Check if there are any changes if [[ $(git rev-list HEAD...origin/"$current_branch" --count) -eq 0 ]]; then - echo -e "${GREEN}Repository is already up-to-date. Do not run git pull before this script. Exiting.${RESET}" + echo -e "${GREEN}Repository is already up-to-date. Do not run git pull before this script. Exiting...${RESET}" exit 0 fi -echo -e "${CYAN}Excluding files and folders: ${excludes[@]}${RESET}" +echo -e "${CYAN}Excluding files and folders that remain untouched: ${excludes[@]}${RESET}" -# Then check which files have been modified by the user since the last update to preserve user configurations +# Then check which files have been customized by the user since the last update to preserve user configurations modified_files=() # Find all files in the specified folders and their subfolders @@ -99,12 +99,12 @@ echo # Output all modified files if [[ ${#modified_files[@]} -gt 0 ]]; then - echo -e "${MAGENTA}The following files have been modified since the last update:${RESET}" + echo -e "${MAGENTA}Customized Files detected: ${RESET}The following files have been customized by you or your system:" for file in "${modified_files[@]}"; do echo -e "${BLUE}$file${RESET}" done else - read -rp "No files found that have been modified since the last update. All files will be replaced. Are you sure you want to continue? [Y/n] " REPLY + read -rp "${YELLOW}No files detected that have been customized since the last update. All files will be replaced. Are you sure you want to continue? [Y/n] ${RESET}" REPLY echo if [[ $REPLY =~ ^[Nn]$ ]]; then echo -e "${RED}Exiting.${RESET}" @@ -158,7 +158,7 @@ case $REPLY in fi ;; *) - echo -e "${GREEN}Keeping every modified file${RESET}" + echo -e "${GREEN}Keeping every customized file${RESET}" ;; esac @@ -190,8 +190,9 @@ if ! git pull; then fi done done - echo -e "${GREEN}New dotfiles have been copied. Cleaning up temporary folder.${RESET}" + echo -e "${GREEN}New dotfiles have been copied. Cleaning up temporary folder...${RESET}" rm -rf "$temp_folder" + echo -e "${GREEN}Done. You may exit now.${RESET}" exit 0 fi @@ -209,3 +210,6 @@ for folder in "${folders[@]}"; do fi done done + +echo -e "${GREEN}Done. You may exit now.${RESET}" + From 9378ac0263915b6a5dd483d7427a50bd756d0614 Mon Sep 17 00:00:00 2001 From: H0mire Date: Wed, 22 May 2024 17:28:41 +0200 Subject: [PATCH 02/12] added temp file for testing purposes --- temp2.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 temp2.txt diff --git a/temp2.txt b/temp2.txt new file mode 100644 index 000000000..e69de29bb From 6749a64b214b3cfe175e967f0751c57b3d7506af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janik=20Michael=20M=C3=BCller?= <45454768+H0mire@users.noreply.github.com> Date: Wed, 22 May 2024 17:29:00 +0200 Subject: [PATCH 03/12] Delete temp.txt --- temp.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 temp.txt diff --git a/temp.txt b/temp.txt deleted file mode 100644 index e69de29bb..000000000 From fc445adeec245242b9dbe84841b22a47f3532944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janik=20Michael=20M=C3=BCller?= <45454768+H0mire@users.noreply.github.com> Date: Wed, 22 May 2024 17:29:15 +0200 Subject: [PATCH 04/12] Delete temp2.txt --- temp2.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 temp2.txt diff --git a/temp2.txt b/temp2.txt deleted file mode 100644 index e69de29bb..000000000 From 87b88a9fd3cf11641131b30c8df81ed691487b60 Mon Sep 17 00:00:00 2001 From: H0mire Date: Wed, 22 May 2024 17:33:21 +0200 Subject: [PATCH 05/12] for testing purposes --- temp3.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 temp3.txt diff --git a/temp3.txt b/temp3.txt new file mode 100644 index 000000000..e69de29bb From d18d00e3a9707b4b9eb769c146b0ecee0e859ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janik=20Michael=20M=C3=BCller?= <45454768+H0mire@users.noreply.github.com> Date: Wed, 22 May 2024 15:37:01 +0000 Subject: [PATCH 06/12] Renamed --- temp3.txt => temp3_renamed.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename temp3.txt => temp3_renamed.txt (100%) diff --git a/temp3.txt b/temp3_renamed.txt similarity index 100% rename from temp3.txt rename to temp3_renamed.txt From 576d52678b6c5bd384fe549f2b9e52080be10046 Mon Sep 17 00:00:00 2001 From: H0mire Date: Wed, 22 May 2024 21:17:07 +0200 Subject: [PATCH 07/12] Finished prototype, next step will be testing --- update-dots.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/update-dots.sh b/update-dots.sh index 7fbc0b854..90258b594 100644 --- a/update-dots.sh +++ b/update-dots.sh @@ -190,12 +190,57 @@ if ! git pull; then fi done done + + # run diff command to determine which files do only exist in the old dotfiles + diff_files=$(diff -qr "$base" "$temp_folder" | grep -E "^Only in $base" | awk '{print $4}') + for file in $diff_files; do + if ! file_in_excludes "$file" && [[ ! " ${modified_files[*]} " =~ " $file " ]]; then + echo -e "${YELLOW}File $file does not exist in the new dotfiles. Deleting...${RESET}" + if [[ -e "$HOME/$file" ]]; then + rm -rf "$HOME/$file" + fi + fi + done + echo -e "${GREEN}New dotfiles have been copied. Cleaning up temporary folder...${RESET}" rm -rf "$temp_folder" echo -e "${GREEN}Done. You may exit now.${RESET}" exit 0 fi + +# Check git diff to determine which files have been removed and which have been renamed +deleted_files=() +renamed_files=() + +# Extract deleted files and save to variable +deleted_files=$(git diff --name-status @{1} | awk '$1 == "D" {print $2}') + +# Extract renamed files and save to variable +renamed_files=$(git diff --name-status @{1} | awk '$1 ~ /^R/ {print $2, "->", $3}') + + +files_to_remove=() + +for file in $files_to_remove; do + + if ! file_in_excludes "$file" && [[ ! " ${modified_files[*]} " =~ " $file " ]]; then + files_to_remove+=("$file") + fi +done +for file in $files_renamed; do + if ! file_in_excludes "$file" && [[ ! " ${modified_files[*]} " =~ " $file " ]]; then + files_renamed+=("$file") + fi +done + +# Remove files +for file in "${files_to_remove[@]}"; do + echo -e "${YELLOW}Removing $file ...${RESET}" + rm -rf "$HOME/$file" +done + + # Replace unmodified files for folder in "${folders[@]}"; do find "$folder" -print0 | while IFS= read -r -d '' file; do From 637e3cea3b0e475d97abfeeaa989c79d9410eef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janik=20Michael=20M=C3=BCller?= <45454768+H0mire@users.noreply.github.com> Date: Wed, 22 May 2024 21:19:06 +0200 Subject: [PATCH 08/12] Create temp4.txt --- temp2.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 temp2.txt diff --git a/temp2.txt b/temp2.txt new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/temp2.txt @@ -0,0 +1 @@ + From 3319021d959a09a636ea247f1d42774b4e1d389b Mon Sep 17 00:00:00 2001 From: H0mire Date: Wed, 22 May 2024 21:23:45 +0200 Subject: [PATCH 09/12] bugfixes --- update-dots.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/update-dots.sh b/update-dots.sh index 90258b594..8b4408a0a 100644 --- a/update-dots.sh +++ b/update-dots.sh @@ -72,7 +72,7 @@ if [[ $(git rev-list HEAD...origin/"$current_branch" --count) -eq 0 ]]; then echo -e "${GREEN}Repository is already up-to-date. Do not run git pull before this script. Exiting...${RESET}" exit 0 fi -echo -e "${CYAN}Excluding files and folders that remain untouched: ${excludes[@]}${RESET}" +echo -e "${CYAN}Excluding files and folders that remain untouched:${RESET} ${excludes[@]}" # Then check which files have been customized by the user since the last update to preserve user configurations modified_files=() @@ -222,15 +222,15 @@ renamed_files=$(git diff --name-status @{1} | awk '$1 ~ /^R/ {print $2, "->", $3 files_to_remove=() -for file in $files_to_remove; do +for file in $deleted_files; do if ! file_in_excludes "$file" && [[ ! " ${modified_files[*]} " =~ " $file " ]]; then files_to_remove+=("$file") fi done -for file in $files_renamed; do +for file in $renamed_files; do if ! file_in_excludes "$file" && [[ ! " ${modified_files[*]} " =~ " $file " ]]; then - files_renamed+=("$file") + files_to_remove+=("$file") fi done From 58c7ec7d60f37cdfb78eb22c357f9ef5b3b94ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janik=20Michael=20M=C3=BCller?= <45454768+H0mire@users.noreply.github.com> Date: Wed, 22 May 2024 22:03:04 +0000 Subject: [PATCH 10/12] bugfix --- update-dots.sh | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/update-dots.sh b/update-dots.sh index 8b4408a0a..35a948588 100644 --- a/update-dots.sh +++ b/update-dots.sh @@ -191,14 +191,35 @@ if ! git pull; then done done - # run diff command to determine which files do only exist in the old dotfiles - diff_files=$(diff -qr "$base" "$temp_folder" | grep -E "^Only in $base" | awk '{print $4}') - for file in $diff_files; do + deleted_files=() + renamed_files=() + + # Extract deleted files and save to variable + deleted_files=$(git diff --name-status HEAD origin/$current_branch | awk '$1 == "D" {print $2}') + + # Extract renamed files and save to variable + renamed_files=$(git diff --name-status HEAD origin/$current_branch | awk '$1 ~ /^R/ {print $2}') + + + files_to_remove=() + + for file in $deleted_files; do + if ! file_in_excludes "$file" && [[ ! " ${modified_files[*]} " =~ " $file " ]]; then - echo -e "${YELLOW}File $file does not exist in the new dotfiles. Deleting...${RESET}" - if [[ -e "$HOME/$file" ]]; then - rm -rf "$HOME/$file" - fi + files_to_remove+=("$file") + fi + done + for file in $renamed_files; do + if ! file_in_excludes "$file" && [[ ! " ${modified_files[*]} " =~ " $file " ]]; then + files_to_remove+=("$file") + fi + done + + # Remove files + for file in "${files_to_remove[@]}"; do + echo -e "${YELLOW}Removing $file ...${RESET}" + if [[ -f "$HOME/$file" ]]; then + rm -rf "$HOME/$file" fi done @@ -217,7 +238,7 @@ renamed_files=() deleted_files=$(git diff --name-status @{1} | awk '$1 == "D" {print $2}') # Extract renamed files and save to variable -renamed_files=$(git diff --name-status @{1} | awk '$1 ~ /^R/ {print $2, "->", $3}') +renamed_files=$(git diff --name-status @{1} | awk '$1 ~ /^R/ {print $2}') files_to_remove=() @@ -237,7 +258,9 @@ done # Remove files for file in "${files_to_remove[@]}"; do echo -e "${YELLOW}Removing $file ...${RESET}" - rm -rf "$HOME/$file" + if [[ -f "$HOME/$file" ]]; then + rm -rf "$HOME/$file" + fi done From 61148292446782f05096faaedd609bc0673af080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janik=20Michael=20M=C3=BCller?= <45454768+H0mire@users.noreply.github.com> Date: Thu, 23 May 2024 07:35:52 +0000 Subject: [PATCH 11/12] tested and ready for pull request --- update-dots.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update-dots.sh b/update-dots.sh index 35a948588..edeeba126 100644 --- a/update-dots.sh +++ b/update-dots.sh @@ -174,7 +174,7 @@ if ! git pull; then mkdir -p ./cache temp_folder=$(mktemp -d -p ./cache) - git clone https://github.com/end-4/dots-hyprland/ --depth=1 "$temp_folder" + git clone --branch "$current_branch" https://github.com/end-4/dots-hyprland/ --depth=1 "$temp_folder" # Replace the existing dotfiles with the new ones for folder in "${folders[@]}"; do find "$temp_folder/$folder" -print0 | while IFS= read -r -d '' file; do From 4d738a63e931f9d576401f52642236f31a1c43d5 Mon Sep 17 00:00:00 2001 From: H0mire Date: Thu, 23 May 2024 09:48:48 +0200 Subject: [PATCH 12/12] removed temp files --- temp2.txt | 1 - temp3_renamed.txt | 0 2 files changed, 1 deletion(-) delete mode 100644 temp2.txt delete mode 100644 temp3_renamed.txt diff --git a/temp2.txt b/temp2.txt deleted file mode 100644 index 8b1378917..000000000 --- a/temp2.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/temp3_renamed.txt b/temp3_renamed.txt deleted file mode 100644 index e69de29bb..000000000