Skip to main content
added 89 characters in body
Source Link
x-yuri
  • 3.6k
  • 13
  • 46
  • 70

This is not exactly an answer to the question, or it is. It depends on how you look at it. Apparently, bash doesn't support this out of the box. And it's not like for no reason, if you think about it. To implement this it has to write to the history file (while keeping it unduplicated) before executing every command, and read every time it needs history. Do you think a file would still suffice? Well, you might use locks, but considering that some indexing would be in order, it must be easier to just make use of some sort of database. And to top it all, do you really want all shells to have common history? Do you not use Up to reexecute command from the current shell? Do you not use sudo !!?

So what I suggest is KISS (be practical):

shopt -s histappend
HISTCONTROL=erasedups

And whenWhen you want to execute a command in another shell, do history -a, then in another shell history -n, and you're good to go.

This is not exactly an answer to the question, or it is. It depends on how you look at it. Apparently, bash doesn't support this out of the box. And it's not like for no reason, if you think about it. To implement this it has to write to the history file (while keeping it unduplicated) before executing every command, and read every time it needs history. Do you think a file would still suffice? Well, you might use locks, but considering that some indexing would be in order, it must be easier to just make use of some sort of database. And to top it all, do you really want all shells to have common history?

So what I suggest is KISS (be practical):

shopt -s histappend
HISTCONTROL=erasedups

And when you want to execute a command in another shell, do history -a, then in another shell history -n, and you're good to go.

This is not exactly an answer to the question, or it is. It depends on how you look at it. Apparently, bash doesn't support this out of the box. And it's not like for no reason, if you think about it. To implement this it has to write to the history file (while keeping it unduplicated) before executing every command, and read every time it needs history. Do you think a file would still suffice? Well, you might use locks, but considering that some indexing would be in order, it must be easier to just make use of some sort of database. And to top it all, do you really want all shells to have common history? Do you not use Up to reexecute command from the current shell? Do you not use sudo !!?

So what I suggest is KISS (be practical):

shopt -s histappend
HISTCONTROL=erasedups

When you want to execute a command in another shell, do history -a, then in another shell history -n, and you're good to go.

Source Link
x-yuri
  • 3.6k
  • 13
  • 46
  • 70

This is not exactly an answer to the question, or it is. It depends on how you look at it. Apparently, bash doesn't support this out of the box. And it's not like for no reason, if you think about it. To implement this it has to write to the history file (while keeping it unduplicated) before executing every command, and read every time it needs history. Do you think a file would still suffice? Well, you might use locks, but considering that some indexing would be in order, it must be easier to just make use of some sort of database. And to top it all, do you really want all shells to have common history?

So what I suggest is KISS (be practical):

shopt -s histappend
HISTCONTROL=erasedups

And when you want to execute a command in another shell, do history -a, then in another shell history -n, and you're good to go.