How do I tell ZSH to reload itself, as if it's a freshly invoked shell, but without losing the history?
The context for this is that I've spent a long time building my ZSH setup, and I'd hate to lose it if my current machine fails, or the drive gets corrupted, etc. To this end, I've put all my local ZSH config files in a git repository. Nothing new so far.
But now I want to add an 'install' script to the repository, to ease the process of installing my setup on a new machine. Once the files are installed (actually, symlinks created in ${ZDOTDIR-~} that point to the files in the repository), I want the script to reload them, without replacing the current process via exec (and therefore losing the history), and without sourcing the files one-by-one (and risking the possibility that I may load them in the wrong order or miss some other part of the ZSH startup process).
Is there some facility built in to ZSH, or some other way to tell it to reload everything, as if it was a freshly started instance, while preserving the command history?
EDIT: Hah. Um.. hrm.. of course, I've now wiped out my .zshrc and .zlogin, Though the latter is no great hardship (It just had RVM's setup in it, which is easily recovered). The former, however, hurts. Anyone who can tell me how to recover a .zshrc from a shell that has sourced it gets all my super bonus points. An answer to the original question will still be marked as accepted, of course.
I had a problem. I wrote a shell script. Now I have two problems :)
To make it your default shell you must first edit /etc/shells and add the new path. Then you can either run chsh -s /usr/local/bin/zsh or go to System Preferences > Users & Groups > right click your user > Advanced Options... > and then change "Login shell".
Or else you can use open -t . zshrc command to open ~/. zshrc file from your general TextEdit on Mac OS.
The zsh shell provides the . zprofile under the user home directory in order to load profile related configuration. The path is ~/. zprofile and can be used like a bash profile file with zsh commands.
Usually a source ~/.zshrc
should do it.
You can enable the option INC_APPEND_HISTORY
. From the manpage:
INC_APPEND_HISTORY
This options works like APPEND_HISTORY except that new history lines are added to the $HISTFILE incrementally (as soon as they are entered), rather than waiting until the shell exits. The file will still be periodically re-written to trim it when the number of lines grows 20% beyond the value specified by $SAVEHIST (see also the HIST_SAVE_BY_COPY option).
This way you can then do exec zsh
without losing history.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With