Skip to content

Bash shell integration -- exit code is not restored when PROMPT_COMMAND is an array #158090

Description

@CyrilOtheninGirard

Type: Bug

VS Code version: Code - Insiders 1.71.0-insider (eebdf81, 2022-08-12T05:17:00.323Z)
OS version: Windows_NT x64 10.0.19044
Modes:
Sandboxed: Yes
Remote OS version: Linux x64 4.15.0-169-generic

When the original PROMPT_COMMAND is an array:

  1. exit code of last executed command is not restored before executing the commands stored inside the original PROMPT_COMMAND array
  2. __vsc_status is assigned the exit code of the penultimate command stored inside the original PROMPT_COMMAND array

Those 2 bugs are located in this section of file vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh :

__vsc_prompt_cmd_original() {
	__vsc_status="$?"
	# Evaluate the original PROMPT_COMMAND similarly to how bash would normally
	# See https://unix.stackexchange.com/a/672843 for technique
	if [[ ${#__vsc_original_prompt_command[@]} -gt 1 ]]; then
		for cmd in "${__vsc_original_prompt_command[@]}"; do
			__vsc_status="$?"
			eval "${cmd:-}"
		done
	else
		__vsc_restore_exit_code "${__vsc_status}"
		eval "${__vsc_original_prompt_command:-}"
	fi
	__vsc_precmd
}
System Info
Item Value
CPUs AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx (8 x 2096)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 13.93GB (0.50GB free)
Process Argv --crash-reporter-id 1c1378c2-301b-4d2f-9d58-b675e62c231f
Screen Reader no
VM 0%
Item Value
Remote SSH: VM
OS Linux x64 4.15.0-169-generic
CPUs AMD Ryzen 5 PRO 3500U w/ Radeon Vega Mobile Gfx (4 x 2095)
Memory (System) 5.82GB (4.79GB free)
VM 100%
Extensions (2)
Extension Author (truncated) Version
remote-ssh ms- 0.85.2022071315
remote-ssh-edit ms- 0.80.0

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugconfirmedIssue has been confirmed by VS Code Team memberterminal-shell-bashAn issue in the terminal specific to bash, including shell integrationverifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions