4 ms·
bash history had never seemed to work for me between tmux windows. Commands are 'trapped' in their respective window and the last one to close 'wins' and write
by dingaling 11y ago
bash history had never seemed to work for me between tmux windows. Commands are 'trapped' in their respective window and the last one to close 'wins' and writes its history over the others.
So I end-up with never-closing task-based window sessions and occasionally copy-paste commands to a safe file for future reference.
I really should investigate the root cause some day...
- tokenizerrr 11y agoYour shell is likely configured to write to the file, instead of appending to it. shopt -s histappend In your .bashrc should do. To have it write after every command take a look at http://unix.stackexchange.com/a/1292 http://unix.stackexchange.com/a/1292
- gknoy 11y agoSome people dislike it, but I LOVE it. I like being able to run a command, open a new terminal, and be able to control-r to find that command again. It ensures that I don't have race conditions over which terminal writes its history to disk first, as well, so I lost far fewer (zero?) history elements.
- JdeBP 11y agoYou've conflated terminal and shell there. It's an important distinction because, in fact, there's still one race condition with history files, even if you only have /one/ shell running. It's down to the Bourne Again shell not doing atomic updates when it rewrites the history file. It's one of two bugs, the other being systemd sending multiple signals in very quick succession to kill a terminal login session, that in combination cause the effect discussed at https://news.ycombinator.com/item?id=10151861 https://news.ycombinator.com/item?id=10151861 . Far from losing zero or a few history elements, it can in fact result in your losing all of your history.
- bruce_one 11y agohttp://askubuntu.com/questions/67283/is-it-possible-to-make-writing-to-bash-history-immediate http://askubuntu.com/questions/67283/is-it-possible-to-make-... might do it? (In zsh I believe it's: setopt inc_append_history setopt share_history )
- michaelhoffman 11y agoThis is one reason why this method uses a different file for every single shell session.
- unhammer 11y agoPut shopt -s histappend export PROMPT_COMMAND="history -a;$PROMPT_COMMAND" in your ~/.bashrc. Also, if you want fresh history in an already opened window (assuming you added the above), do "history -n". E.g. if you typed "longcommand" in window1, then switch to window2, do "history -n" and uparrow, and "longcommand" will be there.
- joelthelion 11y agoFrankly the whole system is archaic. A much better system would be to have a user daemon centralize history (among other things). The benefits would be numerous: - Better performance - (optional) Sync between concurrent shells - No history overwriting problems / race conditions In addition, this daemon could be used to enable other programs such as autojump. These programs work with the current system, but are based on a hack and as such have needlessly poor performance.
- rkrzr 11y agoIt's not just the history feature that's archaic. Bash itself is quite the abomination, also operating on bytestreams is really error-prone, and then there is the whole tty system.. As much as I like my command line, I think it would be very worthwile to rethink this whole system from scratch.
- thebelal 11y agoThis is IMHO the real benefit to zsh over bash. You can set zsh to share history between sessions and they are interleaved based on the time the commands were run. No more closing a session in the wrong order and losing half of your history for the day.