diff --git a/clean_files.txt b/clean_files.txt index e52d5a9f..fca0130c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -28,6 +28,7 @@ bash_it.sh clean_files.txt install.sh lint_clean_files.sh +uninstall.sh # completions # diff --git a/uninstall.sh b/uninstall.sh index 17712610..032bdb7e 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,31 +1,25 @@ #!/usr/bin/env bash -if [ -z "$BASH_IT" ]; -then - BASH_IT="$HOME/.bash_it" -fi +: "${BASH_IT:=${HOME?}/.bash_it}" -case $OSTYPE in - darwin*) - CONFIG_FILE=.bash_profile - ;; - *) - CONFIG_FILE=.bashrc - ;; -esac +CONFIG_FILE=".bashrc" +if [[ ! -e ~/.bashrc && -e ~/.bash_profile ]]; then + # legacy Mac or WSL or just no backup file + CONFIG_FILE=".bash_profile" +fi BACKUP_FILE=$CONFIG_FILE.bak -if [ ! -e "$HOME/$BACKUP_FILE" ]; then - echo -e "\033[0;33mBackup file $HOME/$BACKUP_FILE not found.\033[0m" >&2 +if [[ ! -e "${HOME?}/$BACKUP_FILE" ]]; then + echo -e "\033[0;33mBackup file ${HOME?}/$BACKUP_FILE not found.\033[0m" >&2 - test -w "$HOME/$CONFIG_FILE" && - mv "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.uninstall" && - echo -e "\033[0;32mMoved your $HOME/$CONFIG_FILE to $HOME/$CONFIG_FILE.uninstall.\033[0m" + test -w "${HOME?}/$CONFIG_FILE" \ + && mv "${HOME?}/$CONFIG_FILE" "${HOME?}/$CONFIG_FILE.uninstall" \ + && echo -e "\033[0;32mMoved your ${HOME?}/$CONFIG_FILE to ${HOME?}/$CONFIG_FILE.uninstall.\033[0m" else - test -w "$HOME/$BACKUP_FILE" && - cp -a "$HOME/$BACKUP_FILE" "$HOME/$CONFIG_FILE" && - rm "$HOME/$BACKUP_FILE" && - echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" + test -w "${HOME?}/$BACKUP_FILE" \ + && cp -a "${HOME?}/$BACKUP_FILE" "${HOME?}/$CONFIG_FILE" \ + && rm "${HOME?}/$BACKUP_FILE" \ + && echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" fi echo ""