> > On 1/11/22 6:24 AM, Tathastu Pandya via Bug reports for the GNU Bourne > Again SHell wrote: > > Just as PROMPT COMMAND thats get executed every time before any commamd. > Is there a way to execute predefined command after every command is > executedeg. Automatically record the exit status of currentky executed > command to history file immeduately after a command ends or ctrl+c or any > break or exit > > My prompt is '\n[\$? = $?]\n\[\e]0;\u@\h:$$:\w\a\]where : \u@\h \npwd : \w\n[$$] $' It starts with '\n[\$? = $?]\n ' which means that it prints the exit value of the last command. Looks like this:
[$? = 0] where : matthew@MONOLITH pwd : ~ [61] $ echo hi there hi there [$? = 0] where : matthew@MONOLITH pwd : ~ [61] $echoi hi Command 'echoi' not found, did you mean: command 'echo' from deb coreutils (8.30-3ubuntu2) Try: sudo apt install <deb name> [$? = 127] where : matthew@MONOLITH pwd : ~ [61] $ I don't see why you can't write a function that would write the status out to the history file directly using some kind of comment in it and call that function in PS1 as the first command. Or maybe you can mess with the history saving commands to add that. I messed with mine to record PWD in the history file for each command. You can surf https://github.com/matthewpersico/personal if you want to try and dig up how I did that.