Incognito Mode for Zsh

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:

  • HISTFILE will 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_precmd function from my custom prompt, it will be redefined to show anonsh instead of the command name or working directory.
  • If the %1~ token for displaying the current path is found in your PS1/PS2/PS3/PS4 prompt variables (or the $base_prompt from my custom .zshrc), then it will be replaced with a literal ... so that clear can’t leave anything problematic behind.
  • clear will 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 $TERM is set to screen.
  • Zsh will be configured to call clear before exiting to clear any scrollback that might otherwise hang around if you are using termcapinfo xterm* ti@:te@ in your .screenrc.

Enjoy. 🙂

CC BY-SA 4.0 Incognito Mode for Zsh by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Geek Stuff. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.