From d44a8175d1d9d4917b71dfbfc3f7ee0a240734d8 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Thu, 22 Jul 2021 16:22:42 +0200 Subject: [PATCH] bootstrap: prune broken links The links are only removed if they are broken and the target was within the dotfiles bin directory. This makes it easier to deal with removed and renamed scripts so I don't have to go hunt for them by hand. --- bootstrap | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/bootstrap b/bootstrap index ee69218..93b5548 100755 --- a/bootstrap +++ b/bootstrap @@ -9,6 +9,8 @@ XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" +DOTFILES_DIR="$(dirname "$(realpath "$0")")" + DIRS=$(cat < $target" + $DRY_RUN || rm -f "$1" + fi + ;; + esac + fi +} + file_link() { # Make sure $1 is a link to $2. target="$(realpath "$2")" if [ "$(readlink "$1")" = "$target" ]; then @@ -155,7 +171,14 @@ EOF file_content "$HOME/.local/etc/git/config.host" "$temp_git" } -task_link_local_commands() { +task_prune_broken_bin() { + heading "Prune broken links to commands" + for cmd in $HOME/.local/bin/*; do + prune_link "$cmd" + done +} + +task_link_local_bin() { heading "Link local commands" for cmd in bin/*; do file_link "$HOME/.local/bin/$(basename "$cmd")" "$cmd" @@ -185,12 +208,14 @@ task_install_nvim_plugins() { } main() { + $DRY_RUN && warn "Dry run: no changes will actually be made." task_gather_user_info task_remove_bash_profile task_ensure_directories task_link_dotfiles task_deploy_templates - task_link_local_commands + task_prune_broken_bin + task_link_local_bin task_link_dircolors task_make_logins_silent task_install_nvim_plugins