Incognito Mode. We all use it from time to time, but, if you’re a heavy terminal user, you might use your terminal as often and in as many diverse ways as your browsers.
…so I thought, why not make an incognito mode for Zsh?
With this script, typing anonsh will recognfigure an open zsh instance in several ways:
HISTFILEwill be unset so you still have a command history, but new entries won’t get copied from RAM to disk and will get erased when you exit the shell.- If you’re using the
zsh_hardstatus_precmdfunction from my custom prompt, it will be redefined to showanonshinstead of the command name or working directory. - If the
%1~token for displaying the current path is found in yourPS1/PS2/PS3/PS4prompt variables (or the$base_promptfrom my custom.zshrc), then it will be replaced with a literal...so thatclearcan’t leave anything problematic behind. clearwill be redefined so that it also uses every method I could find to ask your terminal to clear its scrollback buffer, as well as asking GNU screen to empty its own scrollback buffer if$TERMis set toscreen.- Zsh will be configured to call
clearbefore exiting to clear any scrollback that might otherwise hang around if you are usingtermcapinfo xterm* ti@:te@in your.screenrc.
Enjoy. 🙂
Incognito Mode for Zsh by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.
All comments are moderated. If your comment is generic enough to apply to any post, it will be assumed to be spam. Borderline comments will have their URL field erased before being approved.