-
-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/uninstall: Do not overwrite backup bashrcs
- Loading branch information
1 parent
e339b4d
commit a5bdefb
Showing
3 changed files
with
66 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,77 @@ | ||
#!/usr/bin/env bash | ||
|
||
read -r -p "Are you sure you want to remove Oh My Bash? [y/N] " confirmation | ||
if [ "$confirmation" != y ] && [ "$confirmation" != Y ]; then | ||
echo "Uninstall cancelled" | ||
exit | ||
_omb_uninstall_contains_omb() { | ||
grep -qE '(source|\.)[[:space:]]+.*[/[:space:]]oh-my-bash\.sh' "$1" 2>/dev/null | ||
} | ||
|
||
# Find the latest bashrc that do not source oh-my-bash.sh | ||
_omb_uninstall_find_bashrc_original() { | ||
_omb_uninstall_bashrc_original= | ||
printf '%s\n' "Looking for original bash config..." | ||
IFS=' | ||
' | ||
for _omb_uninstall_file in $(printf '%s\n' ~/.bashrc.omb-backup-?????????????? | sort -r) ~/.bashrc.pre-oh-my-bash; do | ||
[ -f "$_omb_uninstall_file" ] || [ -h "$_omb_uninstall_file" ] || continue | ||
_omb_uninstall_contains_omb "$_omb_uninstall_file" && continue | ||
_omb_uninstall_bashrc_original=$_omb_uninstall_file | ||
break | ||
done | ||
unset _omb_uninstall_file | ||
IFS=' | ||
' | ||
if [ -n "$_omb_uninstall_bashrc_original" ]; then | ||
printf '%s\n' "-> Found at '$_omb_uninstall_bashrc_original'." | ||
else | ||
printf '%s\n' "-> Not found." | ||
fi | ||
} | ||
|
||
read -r -p "Are you sure you want to remove Oh My Bash? [y/N] " _omb_uninstall_confirmation | ||
if [ "$_omb_uninstall_confirmation" != y ] && [ "$_omb_uninstall_confirmation" != Y ]; then | ||
printf '%s\n' "Uninstall cancelled" | ||
unset _omb_uninstall_confirmation | ||
return 0 2>/dev/null || exit 0 | ||
fi | ||
unset _omb_uninstall_confirmation | ||
|
||
echo "Removing ~/.oh-my-bash" | ||
if [ -d ~/.oh-my-bash ]; then | ||
printf '%s\n' "Removing ~/.oh-my-bash" | ||
rm -rf ~/.oh-my-bash | ||
fi | ||
|
||
echo "Looking for original bash config..." | ||
if [ -f ~/.bashrc.pre-oh-my-bash ] || [ -h ~/.bashrc.pre-oh-my-bash ]; then | ||
echo "Found ~/.bashrc.pre-oh-my-bash -- Restoring to ~/.bashrc"; | ||
_omb_uninstall_bashrc_original= | ||
_omb_uninstall_find_bashrc_original | ||
|
||
if [ -f ~/.bashrc ] || [ -h ~/.bashrc ]; then | ||
bashrc_SAVE=".bashrc.omb-uninstalled-$(date +%Y%m%d%H%M%S)"; | ||
echo "Found ~/.bashrc -- Renaming to ~/${bashrc_SAVE}"; | ||
mv ~/.bashrc ~/"${bashrc_SAVE}"; | ||
if ! _omb_uninstall_contains_omb ~/.bashrc; then | ||
printf '%s\n' "uninstall: Oh-my-bash does not seem to be installed in .bashrc." >&2 | ||
if [ -n "$_omb_uninstall_bashrc_original" ]; then | ||
printf '%s\n' "uninstall: The original config was found at '$_omb_uninstall_bashrc_original'." >&2 | ||
fi | ||
printf '%s\n' "uninstall: Canceled." >&2 | ||
unset _omb_uninstall_bashrc_original | ||
return 1 2>/dev/null || exit 1 | ||
fi | ||
|
||
mv ~/.bashrc.pre-oh-my-bash ~/.bashrc; | ||
exec bash; source ~/.bashrc | ||
_omb_uninstall_bashrc_uninstalled= | ||
if [ -e ~/.bashrc ] || [ -h ~/.bashrc ]; then | ||
_omb_uninstall_bashrc_uninstalled=".bashrc.omb-uninstalled-$(date +%Y%m%d%H%M%S)"; | ||
printf '%s\n' "Found ~/.bashrc -- Renaming to ~/${_omb_uninstall_bashrc_uninstalled}"; | ||
mv ~/.bashrc ~/"${_omb_uninstall_bashrc_uninstalled}"; | ||
fi | ||
|
||
echo "Your original bash config was restored. Please restart your session." | ||
if [ -n "$_omb_uninstall_bashrc_original" ]; then | ||
printf '%s\n' "Found $_omb_uninstall_bashrc_original -- Restoring to ~/.bashrc"; | ||
mv "$_omb_uninstall_bashrc_original" ~/.bashrc; | ||
printf '%s\n' "Your original bash config was restored. Please restart your session." | ||
else | ||
sed '/oh-my-bash\.sh/s/^/: #/' ~/"${_omb_uninstall_bashrc_uninstalled:-.bashrc}" >| ~/.bashrc.omb-temp && \ | ||
mv ~/.bashrc.omb-temp ~/.bashrc | ||
fi | ||
|
||
unset _omb_uninstall_bashrc_original | ||
unset _omb_uninstall_bashrc_uninstalled | ||
|
||
echo "Thanks for trying out Oh My Bash. It has been uninstalled." | ||
case $- in | ||
*i*) exec bash; source ~/.bashrc ;; | ||
esac |