@@ -34,6 +34,27 @@ ITERM_SHELL_INTEGRATION_INSTALLED=Yes
34
34
# (including various custom escape sequences).
35
35
ITERM_PREV_PS1=" $PS1 "
36
36
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
+
37
58
# The following chunk of code, bash-preexec.sh, is licensed like this:
38
59
# The MIT License
39
60
#
@@ -481,7 +502,7 @@ function iterm2_prompt_suffix() {
481
502
482
503
function iterm2_print_version_number() {
483
504
iterm2_begin_osc
484
- printf " 1337;ShellIntegrationVersion=15 ;shell=bash"
505
+ printf " 1337;ShellIntegrationVersion=16 ;shell=bash"
485
506
iterm2_end_osc
486
507
}
487
508
@@ -515,7 +536,9 @@ __iterm2_preexec() {
515
536
__bp_set_ret_value " $__iterm2_last_ret_value " " $__bp_last_argument_prev_command "
516
537
}
517
538
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 () {
519
542
__iterm2_last_ret_value=" $? "
520
543
521
544
# Work around a bug in CentOS 7.2 where preexec doesn't run if you press
@@ -526,8 +549,6 @@ function __iterm2_precmd () {
526
549
fi
527
550
iterm2_ran_preexec=" "
528
551
529
-
530
-
531
552
# This is an iTerm2 addition to try to work around a problem in the
532
553
# original preexec.bash.
533
554
# When the PS1 has command substitutions, this gets invoked for each
@@ -598,9 +619,8 @@ function __iterm2_precmd () {
598
619
__bp_set_ret_value " $__iterm2_last_ret_value " " $__bp_last_argument_prev_command "
599
620
}
600
621
601
- # Install my functions
622
+ # Install my function
602
623
preexec_functions+= (__iterm2_preexec)
603
- precmd_functions+= (__iterm2_precmd)
604
624
605
625
iterm2_print_state_data
606
626
iterm2_print_version_number
0 commit comments