rcaloras/bash-preexec

__bp_preexec_invoke_exec invoked on ctrl-C from command line

Closed this issue · 3 comments

When the user ctrl-C at the bash prompt (e.g., begins typing a command, thinks better of it, and presses ctrl-C), the __bp_preexec_invoke_exec() function is invoked, and it finds the previous command from history. I've been unable to find a way for the __bp_preexec_invoke_exec() function to determine if it is invoked because of a command, or because the user hit control-c.

@mfthomps thanks for opening an issue. Why are you using __bp_preexec_invoke_exec? That should be an internal function to the script and not one needed to interface with. A typical use case would add functions to the preexec_functions array or define preexec. I'm unable to recreate output for a preexec function when triggering ctrl-C. e.g.

[rcaloras:~] $ preexec() { echo "About to execute: $1"; }
About to execute: pwd
/Users/rcaloras
[rcaloras:~] $ <<ctrl-C>>
[rcaloras:~] $

Thank you for the simple example that helped me realize my problem was due to an error in my .profile that was trapping the SIGINT
Per your question about my use of __bp_preexec_invoke_exec -- I made some modifications to support our use to modify & execute selected commands and tee their stdin & stdout to log files. In those cases, the __bp_preexec_invoke_exec() just returns rather than allowing the command to execute (a second time).
Thanks again.

@mfthomps great to hear. Feel free to re-open if you need any more support with this issue.