Skip to content

Commit ff1fc11

Browse files
authored
Merge pull request microsoft#208960 from cpendery/feat/git-bash-shell-integration
feat: add git-bash support to shell integration
2 parents 9243c3d + 5703cdc commit ff1fc11

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/vs/platform/terminal/common/capabilities/commandDetectionCapability.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ class UnixPtyHeuristics extends Disposable {
500500
}
501501

502502
const enum AdjustCommandStartMarkerConstants {
503-
MaxCheckLineCount = 5,
503+
MaxCheckLineCount = 10,
504504
Interval = 20,
505505
MaximumPollCount = 50,
506506
}
@@ -896,6 +896,15 @@ class WindowsPtyHeuristics extends Disposable {
896896
}
897897
}
898898

899+
// Bash Prompt
900+
const bashPrompt = lineText.match(/^(?<prompt>.*\$)/)?.groups?.prompt;
901+
if (bashPrompt) {
902+
const adjustedPrompt = this._adjustPrompt(bashPrompt, lineText, '$');
903+
if (adjustedPrompt) {
904+
return adjustedPrompt;
905+
}
906+
}
907+
899908
// Python Prompt
900909
const pythonPrompt = lineText.match(/^(?<prompt>>>> )/g)?.groups?.prompt;
901910
if (pythonPrompt) {

src/vs/platform/terminal/node/terminalEnvironment.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ export function getShellIntegrationInjection(
161161
envMixin['VSCODE_SUGGEST'] = '1';
162162
}
163163
return { newArgs, envMixin };
164+
} else if (shell === 'bash.exe') {
165+
if (!originalArgs || originalArgs.length === 0) {
166+
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Bash);
167+
} else if (areZshBashLoginArgs(originalArgs)) {
168+
envMixin['VSCODE_SHELL_LOGIN'] = '1';
169+
addEnvMixinPathPrefix(options, envMixin);
170+
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Bash);
171+
}
172+
if (!newArgs) {
173+
return undefined;
174+
}
175+
newArgs = [...newArgs]; // Shallow clone the array to avoid setting the default array
176+
newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot);
177+
return { newArgs, envMixin };
164178
}
165179
logService.warn(`Shell integration cannot be enabled for executable "${shellLaunchConfig.executable}" and args`, shellLaunchConfig.args);
166180
return undefined;
@@ -310,16 +324,18 @@ shellIntegrationArgs.set(ShellIntegrationExecutable.PwshLogin, ['-l', '-noexit',
310324
shellIntegrationArgs.set(ShellIntegrationExecutable.Zsh, ['-i']);
311325
shellIntegrationArgs.set(ShellIntegrationExecutable.ZshLogin, ['-il']);
312326
shellIntegrationArgs.set(ShellIntegrationExecutable.Bash, ['--init-file', '{0}/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh']);
313-
const loginArgs = ['-login', '-l'];
327+
const pwshLoginArgs = ['-login', '-l'];
328+
const shLoginArgs = ['--login', '-l'];
329+
const shInteractiveArgs = ['-i', '--interactive'];
314330
const pwshImpliedArgs = ['-nol', '-nologo'];
315331

316332
function arePwshLoginArgs(originalArgs: string | string[]): boolean {
317333
if (typeof originalArgs === 'string') {
318-
return loginArgs.includes(originalArgs.toLowerCase());
334+
return pwshLoginArgs.includes(originalArgs.toLowerCase());
319335
} else {
320-
return originalArgs.length === 1 && loginArgs.includes(originalArgs[0].toLowerCase()) ||
336+
return originalArgs.length === 1 && pwshLoginArgs.includes(originalArgs[0].toLowerCase()) ||
321337
(originalArgs.length === 2 &&
322-
(((loginArgs.includes(originalArgs[0].toLowerCase())) || loginArgs.includes(originalArgs[1].toLowerCase())))
338+
(((pwshLoginArgs.includes(originalArgs[0].toLowerCase())) || pwshLoginArgs.includes(originalArgs[1].toLowerCase())))
323339
&& ((pwshImpliedArgs.includes(originalArgs[0].toLowerCase())) || pwshImpliedArgs.includes(originalArgs[1].toLowerCase())));
324340
}
325341
}
@@ -333,6 +349,9 @@ function arePwshImpliedArgs(originalArgs: string | string[]): boolean {
333349
}
334350

335351
function areZshBashLoginArgs(originalArgs: string | string[]): boolean {
336-
return originalArgs === 'string' && loginArgs.includes(originalArgs.toLowerCase())
337-
|| typeof originalArgs !== 'string' && originalArgs.length === 1 && loginArgs.includes(originalArgs[0].toLowerCase());
352+
if (typeof originalArgs !== 'string') {
353+
originalArgs = originalArgs.filter(arg => !shInteractiveArgs.includes(arg.toLowerCase()));
354+
}
355+
return originalArgs === 'string' && shLoginArgs.includes(originalArgs.toLowerCase())
356+
|| typeof originalArgs !== 'string' && originalArgs.length === 1 && shLoginArgs.includes(originalArgs[0].toLowerCase());
338357
}

src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ __vsc_continuation_end() {
183183
}
184184

185185
__vsc_command_complete() {
186+
if [[ -z "$__vsc_first_prompt" ]]; then
187+
builtin return
188+
fi
186189
if [ "$__vsc_current_command" = "" ]; then
187190
builtin printf '\e]633;D\a'
188191
else
@@ -213,6 +216,7 @@ __vsc_precmd() {
213216
__vsc_command_complete "$__vsc_status"
214217
__vsc_current_command=""
215218
__vsc_update_prompt
219+
__vsc_first_prompt=1
216220
}
217221

218222
__vsc_preexec() {

0 commit comments

Comments
 (0)