I need to know what was the last command executed while setting my bash prompt in the function corresponding to PROMPT_COMMAND. I have code as follows
function bash_prompt_command () {
...
local last_cmd="$(history | tail -n 2 | head -n 1 | tr -s ' ' | cut -d ' ' -f3-)"
[[ ${last_cmd} =~ .*git\s+checkout.* ]] && ( ... )
...
}
Is there is faster(bash built-in way) to know the what was the command which invoked PROMPT_COMMAND. I tried using BASH_COMMAND, but that too does not return the command which actually invoked PROMPT_COMMAND.