From 9ce199c251adc21fd79a8095201886ce89b6c07f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 20 Oct 2021 15:28:59 -0400 Subject: [PATCH 1/2] preexec: set options before load 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. --- bash_it.sh | 3 --- vendor/init.d/preexec.bash | 26 ++++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index 215c33c7..de655e81 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -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 diff --git a/vendor/init.d/preexec.bash b/vendor/init.d/preexec.bash index 296b478a..6cfa7b0a 100644 --- a/vendor/init.d/preexec.bash +++ b/vendor/init.d/preexec.bash @@ -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/../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 From bdfb987f0c6cb4fcbdd34652eca5564f1c03a5a8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 20 Oct 2021 15:50:15 -0400 Subject: [PATCH 2/2] plugin/xterm: don't rely on `$1` _bash-preexec_ passes the "current" command line as `$1`, but this is unreliable and we explicitly discourage it's use. Use `$BASH_COMMAND` instead. --- plugins/available/xterm.plugin.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/available/xterm.plugin.bash b/plugins/available/xterm.plugin.bash index b8747a25..740460e4 100644 --- a/plugins/available/xterm.plugin.bash +++ b/plugins/available/xterm.plugin.bash @@ -30,7 +30,11 @@ precmd_xterm_title() { } preexec_xterm_title() { - set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" + local command_line="${BASH_COMMAND:-${1:-}}" + local directory_name short_command + directory_name="$(_short-dirname)" + short_command="$(_short-command "${command_line}")" + set_xterm_title "${short_command} {${directory_name}} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" } case "${TERM:-dumb}" in