Skip to content

Commit

Permalink
Merge pull request #153027 from microsoft/tyriar/150241
Browse files Browse the repository at this point in the history
Integration with bash-preexec
  • Loading branch information
Tyriar committed Jun 23, 2022
2 parents bc50bab + eb08129 commit da296f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit da296f0

Please sign in to comment.