Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for blesh hooks #1572

Merged
merged 2 commits into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions assets/shell-integration/wezterm.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash

# This file hooks up shell integration for wezterm.
# It is suitable for zsh and bash.
#
Expand All @@ -10,6 +12,7 @@
# WEZTERM_SHELL_SKIP_SEMANTIC_ZONES - disables zones
# WEZTERM_SHELL_SKIP_CWD - disables OSC 7 cwd setting

# shellcheck disable=SC2166
if [ -z "${BASH_VERSION}" -a -z "${ZSH_NAME}" ] ; then
# Only for bash or zsh
return 0
Expand Down Expand Up @@ -380,7 +383,11 @@ fi;

} # end of __wezterm_install_bash_prexec

__wezterm_install_bash_prexec
# blesh provides it's own preexec mechanism which is recommended over bash-preexec
# See https://github.com/akinomyoga/ble.sh/wiki/Manual-%C2%A71-Introduction#user-content-fn-blehook for more details
if [[ ! -v BLE_VERSION ]]; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[ -v var ]] is Bash 4.2 feature. Unfortunately, this will produce error messages in lower versions of Bash such as Bash 3.2 in macOS. [[ ! ${BLE_VERSION-} ]] is the way that works in all the versions of Bash 3.0+.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed 78ea214 which uses the same -n "$foo" test that we use for testing for zsh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I usually don't give a damn about the ancient versions of Darwin.

__wezterm_install_bash_prexec
fi

# This function emits an OSC 7 sequence to inform the terminal
# of the current working directory. It prefers to use a helper
Expand Down Expand Up @@ -435,13 +442,22 @@ function __wezterm_semantic_preexec() {
# Register the various functions; take care to perform osc7 after
# the semantic zones as we don't want to perturb the last command
# status before we've had a chance to report it to the terminal
if [[ -z "${WEZTERM_SHELL_SKIP_SEMANTIC_ZONES}" ]] ; then
precmd_functions+=(__wezterm_semantic_precmd)
preexec_functions+=(__wezterm_semantic_preexec)
if [[ -z "${WEZTERM_SHELL_SKIP_SEMANTIC_ZONES}" ]]; then
if [[ -v BLE_VERSION ]]; then
blehook PRECMD+=__wezterm_semantic_precmd
blehook PREEXEC+=__wezterm_semantic_preexec
else
precmd_functions+=(__wezterm_semantic_precmd)
preexec_functions+=(__wezterm_semantic_preexec)
fi
fi

if [[ -z "${WEZTERM_SHELL_SKIP_CWD}" ]] ; then
precmd_functions+=(__wezterm_osc7)
if [[ -v BLE_VERSION ]]; then
blehook PRECMD+=__wezterm_osc7
else
precmd_functions+=(__wezterm_osc7)
fi
fi

true