0

I'm using zsh in macOS 13.

I sometimes want to just try out a few things in Terminal without wanting to keep any history or log of these once I close the Terminal window/tab. On other occasions I do want to keep the history though. So I created two profiles in Terminal, History and No History and then I launch whichever I need. I've even given both distinct background colours so I know which window is for testing.

I initially thought I'd do that upfront via set +o history under Preference > Profiles > Shell > Startup > Run, but that doesn't quite work.

I don't want to edit the ~/.zshrc because that'd mean no history for those occasions where I do want to keep the history.

I've also tried HISTCONTROL=ignoreboth and then preceding each command with a space, meaning it won't get recorded, but that only seems to work in bash and it's only a workaround and not a solution anyway.

How can I keep no record / history for specified profiles once I close the Terminal window?

Alex Ixeras
  • 1,358

2 Answers2

2

One way is set an environment variable in the run command for the profile.

e.g.

TTT=hello zsh -l

Terminal.app Settings

Then in ~/.zshrc test for that environment variable

mmmmmm
  • 30,160
  • Thanks. Can you let me know what this command does? — I've had a look, but I don't have a .zshrc, only a .zsh_history and a .zsh_sessions. – Alex Ixeras Nov 08 '22 at 10:37
  • It sets an environment variable TTT. You can test it with an if statement to alter history configuration. Use echo $TTT to see what its value is – mmmmmm Nov 08 '22 at 12:00
  • Thanks, but what does setting TTT to hello bring about? And what is zsh -l for? – Alex Ixeras Nov 08 '22 at 12:09
  • You need to look at some zsh tutorials as these are basic shell issues. Setting TTT allows zsh to use if statements depending on its value. zsh -l starts zsh as a login shell which is what Terminal.app does – mmmmmm Nov 08 '22 at 12:49
  • Sorry, maybe I should've been clearer: I was wondering what if-statement is executed with TTT and why starting a login shell would not keep a history. – Alex Ixeras Nov 09 '22 at 13:04
  • Those questions show that you need to read some tutorials as they are too long to answer in comments and possibly in answers here. See zsh manuals https://zsh.sourceforge.io/Guide/zshguide.html – mmmmmm Nov 09 '22 at 13:33
  • @AlexIxeras: You do have a text editor, don't you? So if you have not created a .zshrc yet, use the text editor to create the file... – user1934428 Nov 10 '22 at 09:35
1

From https://unix.stackexchange.com/questions/692913/temporarily-disable-history-in-zsh: you could try running the command unset HISTFILE on startup (instead of set +o history).

See also How to disable .zsh_history & .zsh_sessions on macOS? for another option.

(The first of these, unset HISTFILE, works for me. I haven't tried the second. This is with Ventura 13.0, in case the version of OS X matters.)