5 ms·
If that's your use case, here's another game changer (one line bashrc change to make bash_history changes immediately, rather than upon shell exit, e.g. when yo
by xxxtentachyon 4y ago
If that's your use case, here's another game changer (one line bashrc change to make bash_history changes immediately, rather than upon shell exit, e.g. when you end your tmux session): https://web.archive.org/web/20090815205011/http://www.cuberick.com/2008/11/update-bash-history-in-realtime.html https://web.archive.org/web/20090815205011/http://www.cuberi...
- drekipus 4y agoOh wow thank you for this.
- CuteDepravity 4y agoMeta question : do you keep the archive.org link of the article in your favorite or did you manually look up the link before posting? Or maybe an extension that does that automatically?
- yesenadam 4y agoThank you!! Why on earth isn't that the default. It always seemed weird that with multiple bash windows open, the commands from most of them weren't added to the history.
- noxvilleza 4y agoMy guesses are that it's on-close so you can follow the per-shell history slightly easier (rather than it being interleaved from multiple shells?), or reducing disk writes?
- bombcar 4y agoThey don’t interlace which can be nice
- dtgriscom 4y agoI often have three or more terminals open, doing different tasks in each; I also often have cycles of work where I'll repeat the last three commands again (three up-arrows and a return). This breaks if one terminal's commands get inserted into another terminal's history.
- aidenn0 4y agoMy solution is I immediately record the commands, but do not load them. That way new terminals get all the history, but old terminals keep their flow.
- geysersam 4y agoBut if you go back later, the chains of commands from different terminals are interlaced right?
- aidenn0 4y agoTo some degree; it depends on the amount of multitasking. I mainly care about which commands in which order when I'm looking at recent commands from that terminal; otherwise I use C-r.
- flyaway123 4y agoComment from the author: "Ted, the change I suggest doesn't affect the independence of your sessions as you suggest. Each shell maintains a unique history in memory so modifying the history file has no affect on running terminals. The only time the history file is read is when you start a new terminal. I recommend you try my suggestion. Really, all I am doing is eliminating the race condition that causes the bash history file to have inconsistent data. Thanks for the feedback."
- cstrahan 4y agoExactly this. If you do want to load the history persisted from other shells into the current one, all you have to do (if memory serves) is: $ history -r
- usefulcat 4y agoIt is very useful just be careful when switching between shells and hitting the up arrow to get the previous command, as you may get something from another shell.
- mkl 4y agoThat will only happen if PROMPT_COMMAND also contains "history -c; history -r", right? "history -a" just saves it, but "history -c; history -r" clears memory history and reloads from disk.
- usefulcat 4y agoYes, that's correct. I overlooked that detail while reading the link on a phone, where the text is quite small.
- RustyRussell 4y agoFWIW I get a 503 on that URL. Any chance someone can give me that magic one-liner?
- jdhendrickson 4y agoNot sure what that link had as it's dead for me as well but... PROMPT_COMMAND='history -a' Has always worked for me. Goes in your .bashrc from the FM PROMPT_COMMAND ¶ If this variable is set, and is an array, the value of each set element is interpreted as a command to execute before printing the primary prompt ($PS1). If this is set but not an array variable, its value is used as a command to execute instead.
- e12e 4y agoLooks like it is still down - but see eg: https://askubuntu.com/questions/67283/is-it-possible-to-make-writing-to-bash-history-immediate#67306 https://askubuntu.com/questions/67283/is-it-possible-to-make... To wit: > It says to put those commands in the .bashrc config: shopt -s histappend PROMPT_COMMAND="history -a;$PROMPT_COMMAND" > The first command changes the history file mode to append and the second configures the history -a command to be run at each shell prompt. The -a option makes history immediately write the current/new lines to the history file. I used to have something like this set up on my Linux laptop - the downside is that seperate shell/terminals/windows/tabs don't keep seperate history - so if you eg start a server in shell one (rails s), start editor in two - then go back to one and ctrl-c out - up arrow will now give you "vim" not "rails s". The problem compounds if you ping, or curl in another shell etc.
- dbtc 4y agofor zsh setopt inc_append_history
- Tcepsa 4y agoThis is literally going to change my life! T_T
- McUsr 4y agoI have used that for years, but there are downsides to the approach as well. So, you revisit a window, and you want to start from where you left, but now, you might maybe wade through 100's of commands before you get back to that point in time. There are fixes for this too of course, my point is, that it doesn't come without side effects, and that is maybe why it isn't set as default behaviour. At least in a pre 'fzf/atuin/smenu' world. I prefer smenu's history search, even if I consider myself a heavy fzf user.
- CorrectHorseBat 4y agoI did that once (or it might have been something similar with the same effect, don't remember) and after a while it made my terminals super slow.