fix(installer): avoid history backup name collisions

Co-authored-by: robbyrussell <257+robbyrussell@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-09-06 00:15:00 +00:00
committed by GitHub
co-authored by robbyrussell
parent ce6ebd3d8d
commit bc6faea85b
+7 -10
View File
@@ -414,17 +414,14 @@ setup_zshrc() {
case " $hist_backed_up " in case " $hist_backed_up " in
*" $hist "*) continue ;; *" $hist "*) continue ;;
esac esac
hist_backup="${hist}.pre-oh-my-zsh" hist_backup_base="${hist}.pre-oh-my-zsh"
hist_backup="$hist_backup_base"
if [ -e "$hist_backup" ]; then if [ -e "$hist_backup" ]; then
hist_backup="${hist_backup}-$(date +%Y-%m-%d_%H-%M-%S)" hist_backup_i=0
if [ -e "$hist_backup" ]; then while [ -e "$hist_backup" ]; do
fmt_error "$hist_backup exists. Can't back up $hist" hist_backup_i=$((hist_backup_i + 1))
fmt_error "re-run the installer again in a couple of seconds" hist_backup="${hist_backup_base}-$(date +%Y-%m-%d_%H-%M-%S)-${hist_backup_i}"
if ! mv "$OLD_ZSHRC" "$zdot/.zshrc"; then done
fmt_error "could not restore $zdot/.zshrc from backup"
fi
exit 1
fi
fi fi
if cp -p "$hist" "$hist_backup"; then if cp -p "$hist" "$hist_backup"; then
echo "${FMT_GREEN}Backing up your command history to ${hist_backup}${FMT_RESET}" echo "${FMT_GREEN}Backing up your command history to ${hist_backup}${FMT_RESET}"