Files
bootstrap/commands/uninstall.sh

53 lines
1.9 KiB
Bash

# Command: uninstall (bye)
# Removes bootstrap CLI and cleans up shell configuration files
# Source libraries if needed (should already be sourced by routes.sh, but just in case)
if [ -z "${_LIB_SHELL_CONFIG_SOURCED:-}" ]; then
_LIB_DIR="${BOOTSTRAP_DIR:-$HOME/.config/bootstrap}/lib"
. "$_LIB_DIR/shell_config.sh"
fi
log_info "Removing bootstrap CLI completely..."
# Get targets using the library function
IFS=' ' read -ra target_files <<< "$(get_shell_configs)"
for config_file in "${target_files[@]}"; do
# Remove loader setup block
remove_block "$config_file" "bootstrap-cli setup"
# Remove old embedded b function block
remove_block "$config_file" "bootstrap-cli b function"
# Remove bash_aliases setup block if present
remove_block "$config_file" "bootstrap-cli bash_aliases setup"
done
# Clean up bootstrap-specific aliases from ~/.bash_aliases if the file exists
if [ -f "$HOME/.bash_aliases" ]; then
log_info "Cleaning up bootstrap aliases from ~/.bash_aliases..."
# 1. Remove the 'bat alias' block if it was injected there
remove_block "$HOME/.bash_aliases" "bat alias"
# 2. Remove specific aliases added by bootstrap (e.g. vim -> nvim)
if grep -q '^alias vim="nvim"$' "$HOME/.bash_aliases" 2>/dev/null; then
local tmp_file
tmp_file=$(mktemp)
sed '/^alias vim="nvim"$/d' "$HOME/.bash_aliases" > "$tmp_file"
cat "$tmp_file" > "$HOME/.bash_aliases"
rm -f "$tmp_file"
fi
# Remove ~/.bash_aliases entirely if it is empty (size 0) after our cleanup
if [ ! -s "$HOME/.bash_aliases" ]; then
log_info "Removing empty ~/.bash_aliases..."
rm -f "$HOME/.bash_aliases"
fi
fi
# Remove the installation directory
rm -rf "${BOOTSTRAP_DIR:-$HOME/.config/bootstrap}"
log_success "Bootstrap CLI removed successfully. (Note: Run 'unset -f b' to clear it from the current session)"