mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 04:10:09 +00:00
installer: use timestamped backups to preserve all old zshrcs
This commit is contained in:
parent
153f5e11ed
commit
43b3126b5c
2 changed files with 28 additions and 9 deletions
|
@ -84,10 +84,28 @@ setup_ohmyzsh() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_zshrc() {
|
setup_zshrc() {
|
||||||
|
# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
|
||||||
|
# with datestamp of installation that moved them aside, so we never actually
|
||||||
|
# destroy a user's original zshrc
|
||||||
echo "${BLUE}Looking for an existing zsh config...${RESET}"
|
echo "${BLUE}Looking for an existing zsh config...${RESET}"
|
||||||
|
|
||||||
|
# Must use this exact name so uninstall.sh can find it
|
||||||
|
OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
|
||||||
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
|
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
|
||||||
echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${RESET}"
|
if [ -e "$OLD_ZSHRC" ]; then
|
||||||
mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh
|
OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
|
||||||
|
if [ -e "$OLD_OLD_ZSHRC" ]; then
|
||||||
|
error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
|
||||||
|
error "re-run the installer again in a couple of seconds"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
|
||||||
|
|
||||||
|
echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
|
||||||
|
"${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
|
||||||
|
fi
|
||||||
|
echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
|
||||||
|
mv ~/.zshrc "$OLD_ZSHRC"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"
|
echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"
|
||||||
|
|
|
@ -10,16 +10,17 @@ if [ -d ~/.oh-my-zsh ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Looking for original zsh config..."
|
echo "Looking for original zsh config..."
|
||||||
if [ -f ~/.zshrc.pre-oh-my-zsh ] || [ -h ~/.zshrc.pre-oh-my-zsh ]; then
|
ZSHRC_ORIG=~/.zshrc.pre-oh-my-zsh
|
||||||
echo "Found ~/.zshrc.pre-oh-my-zsh -- Restoring to ~/.zshrc";
|
if [ -e "$ZSHRC_ORIG" ]; then
|
||||||
|
echo "Found $ZSHRC_ORIG -- Restoring to ~/.zshrc"
|
||||||
|
|
||||||
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
|
if [ -e ~/.zshrc ]; then
|
||||||
ZSHRC_SAVE=".zshrc.omz-uninstalled-$(date +%Y%m%d%H%M%S)";
|
ZSHRC_SAVE=~/.zshrc.omz-uninstalled-$(date +%Y-%m-%d_%H-%M-%S)
|
||||||
echo "Found ~/.zshrc -- Renaming to ~/${ZSHRC_SAVE}";
|
echo "Found ~/.zshrc -- Renaming to ${ZSHRC_SAVE}"
|
||||||
mv ~/.zshrc ~/"${ZSHRC_SAVE}";
|
mv ~/.zshrc "${ZSHRC_SAVE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mv ~/.zshrc.pre-oh-my-zsh ~/.zshrc;
|
mv "$ZSHRC_ORIG" ~/.zshrc
|
||||||
|
|
||||||
echo "Your original zsh config was restored. Please restart your session."
|
echo "Your original zsh config was restored. Please restart your session."
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue