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 showanonsh
instead of the command name or working directory. - If the
%1~
token for displaying the current path is found in yourPS1
/PS2
/PS3
/PS4
prompt variables (or the$base_prompt
from my custom.zshrc
), then it will be replaced with a literal...
so thatclear
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 toscreen
.- Zsh will be configured to call
clear
before 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.