rcaloras / bash-preexec

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

official way to detect whether bash-preexec is loaded #122

Closed FranklinYu closed 2 years ago

FranklinYu commented 2 years ago
  1. [[ "$(declare -p preexec_functions)" =~ "declare -a" ]] 2>/dev/null
  2. [[ -n ${__bp_imported} ]]

Concern with 1 is that the test suite doesn’t guarantee existence of variable preexec_functions; note that in a fresh Zsh, this variable is undeclared. Concern with 2 is that I’m not sure whether this is part of the public API (given the __bp_ prefix).

rcaloras commented 2 years ago

I'd advocate for 2. It's not intended to be part of the public api (given the prefix), but I think it's much more practical. If needed feel free to submit a PR to rename to remove the underscores.

dimo414 commented 2 years ago

__bp_imported is what I check as well: https://github.com/dimo414/prompt.gem/blob/8a8d415052abd51f7c089df8473b7b64a7768d65/commands.sh#L25