1

I want infinite history, because I type a lot of commands I can forget at the spot and would like to have it stored somewhere as a reference. But by just setting HISTSIZE and HISTFILESIZE it does not work good because IIRC the commands are stored only when terminal window is closed, and tends to overwrite each other. So my current setting is this:

export HISTCONTROL=ignoredups:erasedups  # no duplicate entries
export HISTSIZE=100000                   # big big history
export HISTFILESIZE=100000               # big big history
shopt -s histappend                      # append to history, don't overwrite it

however this has one drawback. When using multi-pane "terminal app" like terminator, the history order for each pane is incorrect, as IIUC, then I won't lose any command, but history is central, thus separate terminals cannot say what was their last command.

I need not to stick to bash history management, I have no issue with anything else which would solve this, ie: no lost commands, each terminal is capable to find any command while still being able to scroll back in time in order this specific terminal invoked the commands. If you have experience with McFly or anything else which would work, please advise. However I'd rather not like to steer away from bash, because it's more commonly used, and I need to be able to share scripts with majority or people.

Motivation: imagine one terminator app, splitted into several virtual terminals while doing testing. I want to invoke some commands it "its" specific pane for clarity. It would be speedup for me, if I could be able just hit up-enter to rerun previous command, which I cannot, because actions from other panes changes the order.

Thanks!

2 Answers 2

0

Separate terminals cannot say what was their last command

A hacky solution is to mess around with the history file name (HISTFILE):

By default, history is stored in ~/.bash_history file. Add the following line to the .bash_profile and relogin to the bash shell, to store the history command in .commandline_warrior file instead of .bash_history file. I’m yet to figure out a practical use for this. I can see this getting used when you want to track commands executed from different terminals using different history file name.

# vi ~/.bash_profile
HISTFILE=/root/.commandline_warrior

Source Hack 56. Change the history file name using HISTFILE

I will leave it up to you to figure out the precise mechanics, but this should be enough to get you started.

It would be nice, for example, to use the terminal window title or something similar to set the history file name but I don't know enough bash to figure out how to do that automatically.

0

I have this on .bashrc

PROMPT_COMMAND='echo "$(history 1)" >> ~/history4ever'

It is from this book about shell scripting (in pt_BR).

3
  • seems ok.So with this,I could remove export HISTCONTROL=ignoredups:erasedups which does not work reliably anyways, remove also shopt -s histappend to remove interference between shells. Then each shell will only overwrite bash_history when existing and will keep it's own order.File .bash_history would be incomplete and potentially messy, but history4ever would be ordered and complete. And I would have 2 commands: session history and global history. Jan 23, 2020 at 12:54
  • Could you also advice, how to do efficient filtering,not do log cd etc? Sure I can pipe&grep it, but if I don't want to spawn too many greps and use some "daemon"? Jan 23, 2020 at 12:54
  • I don't know how to filter directly on bash, maybe you can filter inside the $(history 1) sub-shell, before it sent to history4ever.
    – Paulo
    Jan 23, 2020 at 13:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .