Skip to content

Commit

Permalink
dorothy: add uninstall action
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Jul 19, 2023
1 parent 8c26f82 commit 4549dd3
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion commands/dorothy
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,28 @@ function dorothy() (
fi
}

function remove_shell_configuration {
# bash
config-helper --file="$HOME/.bash_profile" -- \
--find='source ".+?" # Dorothy' --replace=''
config-helper --file="$HOME/.bashrc" -- \
--find='source ".+?" # Dorothy' --replace=''

# zsh
mkdir -p "$ZDOTDIR"
config-helper --file="$ZDOTDIR/.zshrc" -- \
--find='source ".+?" # Dorothy' --replace=''
config-helper --file="$ZDOTDIR/.zprofile" -- \
--find='source ".+?" # Dorothy' --replace=''
config-helper --file="$HOME/.zshenv" -- \
--find='ZDOTDIR=.+' --replace="ZDOTDIR=\"$ZDOTDIR\""

# fish
mkdir -p "$HOME/.config/fish"
config-helper --file="$HOME/.config/fish/config.fish" -- \
--find='source ".+?" # Dorothy' --replace=''
}

# =====================================
# Actions: Install, Update, Trial

Expand All @@ -1015,7 +1037,31 @@ function dorothy() (
echo-segment --g1='Install Dorothy'

# log success
echo-style --success='Dorothy is now setup. ' --notice='Restart your terminal.'
echo-style --success='Dorothy is now setup.' ' ' --notice='Restart your terminal.'
}

function act_uninstall {
ensure_dorothy_configured
assert_dorothy_configured
ensure_minimal_dependencies

echo-segment --h1='Uninstall Dorothy'
remove_shell_configuration
echo-segment --g1='Uninstall Dorothy'

# log success and instructions for removal
echo-style --success='Dorothy is now uninstalled.' ' ' --notice='Restart your terminal.'
local paths=()
if test -d "$DOROTHY"; then
paths+=("$DOROTHY")
fi
if test -d "$DOROTHY/user"; then
paths+=("$(fs-realpath -- "$DOROTHY/user")")
fi
if test "${#paths[@]}" -ne 0; then
echo 'Once you have restarted your terminal, you can delete Dorothy by removing the following paths:'
echo-lines "${paths[@]}"
fi
}

function act_update {
Expand Down

0 comments on commit 4549dd3

Please sign in to comment.