Make dotfiles reversible
This commit is contained in:
+29
-11
@@ -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 <<CONFIG > ssh/.ssh/extra.conf
|
||||
EnableEscapeCommandline yes
|
||||
CONFIG
|
||||
fi
|
||||
apply_dotfile ssh
|
||||
operation ssh
|
||||
|
||||
restore_from_adoption
|
||||
|
||||
Reference in New Issue
Block a user