Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bill99

macrumors regular
Original poster
Aug 16, 2019
102
6
Hello forum,

I often need to repeat/re-use (with arrow up key) a long command and therefore would use a dedicated Terminal for that command.
But after rebooting the iMac, the typing history of other Terminals are shown/available in this dedicated Terminal :(


Question:
Is there a way that only the history of the command I typed in that Terminal is beeing added/available in the history?


Thank's a lot!

Bill
 

posguy99

macrumors 68020
Nov 3, 2004
2,284
1,531
With which shell? This is all about how you configure whatever shell you are using, and has nothing to do with Terminal.app.
 

posguy99

macrumors 68020
Nov 3, 2004
2,284
1,531
There is only one history, stored in ~/.zsh_history
Well, of course, that's incorrect.

The OP might not be using zsh.
If they are using zsh, they might or might not be setting HISTFILE.
If they are using zsh, they might or not be setting share_history.

An easy way to do what the OP asked, would be to set HISTFILE in the interactive shell init, and postfix the name with a deterministic number, such as the TTY the shell is connected to.

I do this:

Code:
mkdir -p $FOLDER/histfiles          # location of history files
TTY=$(bn $(tty))
HISTFILE=$FOLDER/histfiles/history.${TTY}

There are other ways, I'm sure.
 

bogdanw

macrumors 603
Mar 10, 2009
6,114
3,021
Well, of course, that's incorrect.
Well, of course, it is in fact correct. :)
That is the default configuration, the one that is causing the problem described, on bash or zsh.
While there can be many ways to solve it, it is what it is, not what it could be. :)
If I had to run the same long command repeatedly, I would put in a .command file and just double click it when necessary.
If I had to observe the progress of the command, I would make an AppleScript like the one here https://forums.macrumors.com/threads/automator-applescript-help.2295459/post-29871275 and save it as an app.
 

posguy99

macrumors 68020
Nov 3, 2004
2,284
1,531
Well, of course, it is in fact correct. :)
That is the default configuration, the one that is causing the problem described, on bash or zsh.
While there can be many ways to solve it, it is what it is, not what it could be. :)
If I had to run the same long command repeatedly, I would put in a .command file and just double click it when necessary.
If I had to observe the progress of the command, I would make an AppleScript like the one here https://forums.macrumors.com/threads/automator-applescript-help.2295459/post-29871275 and save it as an app.
Really. Bash names its history file .zsh_history, then. I'm sure you don't believe that.

The OP asks how to solve the problem. Do you have one to offer? I did.
 

bogdanw

macrumors 603
Mar 10, 2009
6,114
3,021
Really. Bash names its history file .zsh_history, then.
Obviously, it's stored in ~/.bash_history
But it’s just one separate file for either, regardless of the number of sessions opened.
Besides the solutions mentioned above, the simplest one would be to use one of them (bash or zsh) only for that command. :)
As a side note, Big Sur has by default a folder ~/.zsh_sessions
 

bill99

macrumors regular
Original poster
Aug 16, 2019
102
6
Sorry that I forgot to mention, that on top of my Terminal-window it's written:

~ -- - zsh
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.