From d8a9c7c7da93006e5ca5e69bfad6fd09f5afd53a Mon Sep 17 00:00:00 2001 From: "Andrew R. M." Date: Tue, 14 Jul 2026 14:38:16 -0400 Subject: [PATCH] Make dotfiles reversible --- apply-dotfiles | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/apply-dotfiles b/apply-dotfiles index bfc7db6..aa6912a 100755 --- a/apply-dotfiles +++ b/apply-dotfiles @@ -5,6 +5,11 @@ apply_dotfile() { stow --adopt -S -t "${HOME}" "${directory_to_stow}" } +revert_dotfile() { + directory_to_stow="${1}" + stow -D -t "${HOME}" "${directory_to_stow}" +} + # Adopt will change the files in stow to match existing files. # We don't want this, we just want to handle existing files gracefully. # We simply adopt all the files and then at the end restore our git repo to undo changes @@ -12,22 +17,35 @@ restore_from_adoption() { git restore . } -apply_dotfile bash -apply_dotfile sh -apply_dotfile readline -apply_dotfile screen +mode_command=${1:-apply} +if [ "${mode_command}" != "apply" ] && [ "${mode_command}" != "revert" ]; then + echo "$0: mode command ("'${1}'") must be apply or revert" 1>&2 + exit 1 +fi -apply_dotfile git -apply_dotfile xdg +operation() { + ${mode_command}_dotfile ${1} +} -apply_dotfile vim +# Create .local/bin to prevent tree folding +mkdir -p ~/.local/bin -apply_dotfile ruby -apply_dotfile python +operation bash +operation sh +operation readline +operation screen + +operation git +operation xdg + +operation vim + +operation ruby +operation python # Only if inside a coder instance if [ -n "${CODER}" ]; then - apply_dotfile gnupg + operation gnupg fi # Check that SSH version is above 9.2 (where EnableEscapeCommandline was added) before conditionally adding @@ -38,6 +56,6 @@ cat < ssh/.ssh/extra.conf EnableEscapeCommandline yes CONFIG fi -apply_dotfile ssh +operation ssh restore_from_adoption