Skip to content

Commit

Permalink
preexec: set options before load
Browse files Browse the repository at this point in the history
By setting `__bp_delay_install`, we avoid any immediate initialization at all. We then override two troublesome functions before calling `__bp_install_after_session_init()`.

The `__bp_install_after_session_init()` function doesn't enable the DEBUG trap, just sets `$PROMPT_COMMAND` to include `__bp_install()`, so the actual final `$PROMPT_COMMAND` is not finished, and DEBUG trap set, until after the first prompt is displayed.
  • Loading branch information
gaelicWizard committed Oct 20, 2021
1 parent 2d1bd82 commit 5fb69dd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 0 additions & 3 deletions bash_it.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,3 @@ if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then
;;
esac
fi

# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040
set +T
26 changes: 24 additions & 2 deletions vendor/init.d/preexec.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# shellcheck shell=bash
# shellcheck disable=1090
source "${BASH_IT}"/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh
# shellcheck disable=SC2034
#
# Load the `bash-preexec.sh` library, and define helper functions

## Prepare, load, fix, and install `bash-preexec.sh`

# Disable immediate `$PROMPT_COMMAND` modification
__bp_delay_install="delayed"

# shellcheck source-path=SCRIPTDIR/vendor/github.com/rcaloras/bash-preexec
source "${BASH_IT?}/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh"

# Block damanaging user's `$HISTCONTROL`
function __bp_adjust_histcontrol() { :; }

# Don't fail on readonly variables
function __bp_require_not_readonly() { :; }

# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040
__bp_enable_subshells= # blank
set +T

# Modify `$PROMPT_COMMAND` now
__bp_install_after_session_init

0 comments on commit 5fb69dd

Please sign in to comment.