Fixes#13156
- Enhanced uninstall script to automatically restore .zshrc from uninstall backup
when no original backup (.zshrc.pre-oh-my-zsh) exists
- Improved install script to create backup even when KEEP_ZSHRC=yes
- Added better user feedback and error handling
- Prevents data loss for users who installed with --keep-zshrc option
The issue occurred when users installed oh-my-zsh with KEEP_ZSHRC=yes
(keeping their existing .zshrc), which didn't create a backup. During
uninstall, their .zshrc would be deleted with no backup to restore.
Now the uninstall process:
1. Creates a timestamped backup of current .zshrc
2. Looks for original backup (.zshrc.pre-oh-my-zsh)
3. If found, restores the original
4. If not found, automatically restores from the uninstall backup
5. Provides clear feedback to the user
This ensures users never lose their .zshrc configuration during uninstall.
When the `git init` call fails, the directory is not created,
so the rm command fails with a not found error. This change
checks whether the directory exists before deleting it.
The previous check only worked if the user could run `sudo` without typing the
password, which is almost none (I checked in Google Cloud Shell so I failed to
notice this).
This new check works whether the user has no sudo privileges, or if it has,
whether they have to type in the password or not.
It should really be easier to check if the user doesn't have privilege without
having to make them type the password.
This fixes the error in Google Cloud Shell, where a password prompt
appears when running `chsh` but the user (hello) does not have a
password.
If ran with `sudo`, the `chsh` command happens without a password
prompt.
* refactor(install.sh): fix static analysis warnings
Clear all warnings and errors raised by shellcheck.net static analysis.
- Replace non-POSIX shell use of `$OSTYPE` by POSIX compliant check on `uname -o`.
- Move variables out of`printf` format string.
- Refactor/simplify string formatters for error and underline.
- Fix expansion of arguments to a single string `$*` rather than individual elements `$@` within the error and underline formatters.
* fix(uname): non-posix -o option
* fix(install.sh): non portable which
Replaced non-portable `which zsh` by portable `command -v zsh`