Occasionally my X11 window manager (i3) locks up, and I'm forced to switch to a Linux virtual console, or SSH into my machine, to regain control.
Usually this happens when I have numerous rxvt windows open, each of which running a bash shell containing tens if not hundreds of lines of useful command-line history collected over many days or weeks.
I'm using shopt -s histappend
so each bash shell will append its history to the history file when it terminates in an orderly manner. Normally this works very well and it will retain all of my history provided I close each shell cleanly with exit
or CTRL-D.
But when my window manager locks up, I can't cleanly exit my bash sessions because there's no way to interact with them. So I've been trying to find a way to _remotely_ terminate a bash shell in a way that will cause it to write its history to the history file.
I've tried sending numerous signals, including SIGHUP
, to both the bash shell process and the containing rxvt process, but none result in a history save.
I've tried to restart i3 but for various reasons this doesn't work (broken RPC socket it appears). Killing the window manager closes all the windows and bash shells and I lose the history from all of them.
I've tried to find a way to inject "CTRL-D" into each shell's stdin
, but as far as I can tell that's not possible.
I know of ways to make bash save history to the history file after every command, but I prefer not to use these as they mess up the history indices (i.e. !nnn
doesn't work because nnn
changes after every command).
Is there a way to do this and rescue my precious history from certain oblivion?