From eb081298c01b4eb843285d45392a6a6c447ae5eb Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 23 Jun 2022 13:01:36 -0700 Subject: [PATCH] Integration with bash-preexec Fixes #150241 --- .../commandDetectionCapability.ts | 7 +++- .../browser/media/shellIntegration-bash.sh | 39 ++++++++++++------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts b/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts index 95e0ebe2499..7c03c1a0685 100644 --- a/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts +++ b/src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts @@ -402,7 +402,7 @@ export class CommandDetectionCapability implements ICommandDetectionCapability { } this._currentCommand.commandFinishedMarker = this._terminal.registerMarker(0); - const command = this._currentCommand.command; + let command = this._currentCommand.command; this._logService.debug('CommandDetectionCapability#handleCommandFinished', this._terminal.buffer.active.cursorX, this._currentCommand.commandFinishedMarker?.line, this._currentCommand.command, this._currentCommand); this._exitCode = exitCode; @@ -422,6 +422,11 @@ export class CommandDetectionCapability implements ICommandDetectionCapability { return; } + // When the command finishes and executed never fires the placeholder selector should be used. + if (this._exitCode === undefined && command === undefined) { + command = ''; + } + if ((command !== undefined && !command.startsWith('\\')) || this._handleCommandStartOptions?.ignoreCommandLine) { const buffer = this._terminal.buffer.active; const timestamp = Date.now(); diff --git a/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh b/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh index 6693a0539a7..24452f966fa 100755 --- a/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh +++ b/src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh @@ -118,20 +118,29 @@ __vsc_preexec() { } # Debug trapping/preexec inspired by starship (ISC) -__vsc_dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')" -if [[ -z "$__vsc_dbg_trap" ]]; then +if [[ -n "${bash_preexec_imported:-}" ]]; then __vsc_preexec_only() { __vsc_status="$?" __vsc_preexec } - trap '__vsc_preexec_only "$_"' DEBUG -elif [[ "$__vsc_dbg_trap" != '__vsc_preexec "$_"' && "$__vsc_dbg_trap" != '__vsc_preexec_all "$_"' ]]; then - __vsc_preexec_all() { - __vsc_status="$?" - builtin eval ${__vsc_dbg_trap} - __vsc_preexec - } - trap '__vsc_preexec_all "$_"' DEBUG + precmd_functions+=(__vsc_prompt_cmd) + preexec_functions+=(__vsc_preexec_only) +else + __vsc_dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')" + if [[ -z "$__vsc_dbg_trap" ]]; then + __vsc_preexec_only() { + __vsc_status="$?" + __vsc_preexec + } + trap '__vsc_preexec_only "$_"' DEBUG + elif [[ "$__vsc_dbg_trap" != '__vsc_preexec "$_"' && "$__vsc_dbg_trap" != '__vsc_preexec_all "$_"' ]]; then + __vsc_preexec_all() { + __vsc_status="$?" + builtin eval ${__vsc_dbg_trap} + __vsc_preexec + } + trap '__vsc_preexec_all "$_"' DEBUG + fi fi __vsc_update_prompt @@ -172,8 +181,10 @@ else __vsc_original_prompt_command=${PROMPT_COMMAND[@]} fi -if [[ -n "$__vsc_original_prompt_command" && "$__vsc_original_prompt_command" != "__vsc_prompt_cmd" ]]; then - PROMPT_COMMAND=__vsc_prompt_cmd_original -else - PROMPT_COMMAND=__vsc_prompt_cmd +if [[ -z "${bash_preexec_imported:-}" ]]; then + if [[ -n "$__vsc_original_prompt_command" && "$__vsc_original_prompt_command" != "__vsc_prompt_cmd" ]]; then + PROMPT_COMMAND=__vsc_prompt_cmd_original + else + PROMPT_COMMAND=__vsc_prompt_cmd + fi fi