Skip to content

Commit 49c0217

Browse files
committed
Update bash shell integration (for issue 9171) and utilities
1 parent 2f03d47 commit 49c0217

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

Resources/shell_integration/iterm2_shell_integration.bash

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ ITERM_SHELL_INTEGRATION_INSTALLED=Yes
3434
# (including various custom escape sequences).
3535
ITERM_PREV_PS1="$PS1"
3636

37+
# A note on execution. When you invoke a command at an interactive prompt the following steps are taken:
38+
#
39+
# 1. The DEBUG trap runs.
40+
# It calls __bp_preexec_invoke_exec
41+
# It runs any registered preexec_functions, including __iterm2_preexec
42+
# 2. The command you executed runs.
43+
# 3. PROMPT_COMMAND runs.
44+
# It runs __bp_precmd_invoke_cmd, which is inserted as the first command in PROMPT_COMMAND.
45+
# It calls any registered precmd_functions
46+
# Then, pre-existing PROMPT_COMMANDs run
47+
# 4. The prompt is shown.
48+
#
49+
# __iterm2_prompt_command used to be run from precmd_functions but then a pre-existing
50+
# PROMPT_COMMAND could clobber the PS1 it modifies. Instead, add __iterm2_prompt_command as the last
51+
# of the "preexisting" PROMPT_COMMANDs so it will be the very last thing done before the prompt is
52+
# shown (unless someone amends PROMPT_COMMAND, but that is on them).
53+
if [[ -n "$PROMPT_COMMAND" ]]; then
54+
PROMPT_COMMAND+=$'\n'
55+
fi;
56+
PROMPT_COMMAND+='__iterm2_prompt_command'
57+
3758
# The following chunk of code, bash-preexec.sh, is licensed like this:
3859
# The MIT License
3960
#
@@ -481,7 +502,7 @@ function iterm2_prompt_suffix() {
481502

482503
function iterm2_print_version_number() {
483504
iterm2_begin_osc
484-
printf "1337;ShellIntegrationVersion=15;shell=bash"
505+
printf "1337;ShellIntegrationVersion=16;shell=bash"
485506
iterm2_end_osc
486507
}
487508

@@ -515,7 +536,9 @@ __iterm2_preexec() {
515536
__bp_set_ret_value "$__iterm2_last_ret_value" "$__bp_last_argument_prev_command"
516537
}
517538

518-
function __iterm2_precmd () {
539+
# Prints the current directory and hostname control sequences. Modifies PS1 to
540+
# add the FinalTerm A and B codes to locate the prompt.
541+
function __iterm2_prompt_command () {
519542
__iterm2_last_ret_value="$?"
520543

521544
# Work around a bug in CentOS 7.2 where preexec doesn't run if you press
@@ -526,8 +549,6 @@ function __iterm2_precmd () {
526549
fi
527550
iterm2_ran_preexec=""
528551

529-
530-
531552
# This is an iTerm2 addition to try to work around a problem in the
532553
# original preexec.bash.
533554
# When the PS1 has command substitutions, this gets invoked for each
@@ -598,9 +619,8 @@ function __iterm2_precmd () {
598619
__bp_set_ret_value "$__iterm2_last_ret_value" "$__bp_last_argument_prev_command"
599620
}
600621

601-
# Install my functions
622+
# Install my function
602623
preexec_functions+=(__iterm2_preexec)
603-
precmd_functions+=(__iterm2_precmd)
604624

605625
iterm2_print_state_data
606626
iterm2_print_version_number

Resources/utilities/utilities.tgz

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)