rcaloras / bash-preexec

⚡ preexec and precmd functions for Bash just like Zsh.
MIT License
876 stars 93 forks source link

Reinstalling Bash-preexec Doesn't Work #94

Closed anhnamtran closed 5 years ago

anhnamtran commented 5 years ago

Hi, I was wondering if there is a way to "reinstall" Bash-preexec.

Desired behavior:

  1. Install BP with source bash-preexec.sh and define the functions.
  2. Work with it in the terminal a little bit.
  3. "Uninstall" by removing bash-preexec.sh and running exec bash.
  4. Work without it just fine.
  5. "Reinstall" by downloading and source bash-preexec.sh and defining the functions.
  6. BP works with the defined functions

Debugging output:

$ echo $PROMPT_COMMAND
__bp_precmd_invoke_cmd; __bp_interactive_mode;
$ echo ${preexec_functions[@]}
preexec
$ echo ${precmd_functions[@]}
precmd
$ trap
trap -- '' SIGTSTP
trap -- '' SIGTTIN
trap -- '' SIGTTOU
trap -- '__bp_preexec_invoke_exec' DEBUG
$ echo $__bp_imported
defined

Actual behavior:

  1. ...
  2. ...
  3. Steps 1 through 5 are the same
  4. ...
  5. BP only runs precmd functions.

Debugging output:

$ echo $PROMPT_COMMAND
__bp_precmd_invoke_cmd; __bp_interactive_mode;
$ echo ${preexec_functions[@]}
preexec
$ echo ${precmd_functions[@]}
precmd
$ trap
trap -- '' SIGTSTP
trap -- '' SIGTTIN
trap -- '' SIGTTOU
$ echo $__bp_imported
defined

As you can see, oddly enough, only the trap is different. I've discovered that it's because exec bash in my terminal does not change $PROMPT_COMMAND.

I looked through the source code in bash-preexec.sh, and saw that you check $PROMPT_COMMAND before creating the trap. I have tried doing export PROMPT_COMMAND="" in my "uninstall" step (after exec bash), but that still created the same behavior as the "Actual" behavior.

I was wondering if I'm doing anything wrong or if there's a cleaner way to uninstall and reinstall BP.

rcaloras commented 5 years ago

@anhnamtran Not sure why the DEBUG trap isn't being reset here. You can also try to add some additional debugging to bash-preexec.sh during the reinstall. The trap should actually be set as part of PROMPT_COMMAND on https://github.com/rcaloras/bash-preexec/blob/9811ba8b7694cdbd9debed931e922b67e439197a/bash-preexec.sh#L323 You can probably add some additional logging either in PROMPT_COMMAND as a part of that line, or just before and after to make sure it's being executed. Bash may be preventing it from being set for some reason as well. Lets see if that additional debugging suggests it's being run. Hope that helps!

rcaloras commented 5 years ago

Closing. Feel free to re-open @anhnamtran if this is still an issue.