Skip to content

Commit e140b96

Browse files
committed
feat: add git-bash support
1 parent 07363f9 commit e140b96

6 files changed

Lines changed: 44 additions & 3 deletions

File tree

src/extension.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ import { TerminalActivationImpl } from './features/terminal/terminalActivationSt
5959
import { getEnvironmentForTerminal } from './features/terminal/utils';
6060
import { PowershellStartupProvider } from './features/terminal/startup/powershellStartup';
6161
import { ShellStartupActivationManagerImpl } from './features/terminal/startup/activateUsingShellStartup';
62-
import { BashStartupProvider } from './features/terminal/startup/bashStartup';
62+
import { BashStartupProvider, GitBashStartupProvider } from './features/terminal/startup/bashStartup';
63+
import { isWindows } from './common/utils/platformUtils';
6364

6465
export async function activate(context: ExtensionContext): Promise<PythonEnvironmentApi> {
6566
const start = new StopWatch();
@@ -86,7 +87,9 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
8687
context.subscriptions.push(envManagers);
8788

8889
const terminalActivation = new TerminalActivationImpl();
89-
const shellStartupProviders = [new PowershellStartupProvider(), new BashStartupProvider()];
90+
const shellStartupProviders = isWindows()
91+
? [new PowershellStartupProvider(), new GitBashStartupProvider()]
92+
: [new PowershellStartupProvider(), new BashStartupProvider()];
9093
const shellStartupActivationManager = new ShellStartupActivationManagerImpl(
9194
context.environmentVariableCollection,
9295
shellStartupProviders,

src/features/terminal/startup/bashStartup.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,41 @@ export class BashStartupProvider implements ShellStartupProvider {
211211
}
212212
}
213213
}
214+
215+
export class GitBashStartupProvider implements ShellStartupProvider {
216+
async isSetup(): Promise<boolean> {
217+
const bashProfiles = await getBashProfiles();
218+
return await isStartupSetup(bashProfiles);
219+
}
220+
async setupScripts(): Promise<boolean> {
221+
const bashProfiles = await getBashProfiles();
222+
return await setupStartup(bashProfiles);
223+
}
224+
async teardownScripts(): Promise<boolean> {
225+
const bashProfiles = await getBashProfiles();
226+
return await removeBashStartup(bashProfiles);
227+
}
228+
async updateEnvVariables(envVars: EnvironmentVariableCollection, env: PythonEnvironment): Promise<void> {
229+
const bashActivation = getActivationCommandForShell(env, TerminalShellType.gitbash);
230+
if (bashActivation) {
231+
const command = getCommandAsString(bashActivation);
232+
envVars.replace(bashActivationEnvVarKey, command);
233+
} else {
234+
envVars.delete(bashActivationEnvVarKey);
235+
}
236+
}
237+
async removeEnvVariables(envVars: EnvironmentVariableCollection): Promise<void> {
238+
envVars.delete(bashActivationEnvVarKey);
239+
}
240+
async getEnvVariables(env?: PythonEnvironment): Promise<Map<string, string | undefined> | undefined> {
241+
if (env) {
242+
const bashActivation = getActivationCommandForShell(env, TerminalShellType.gitbash);
243+
return bashActivation
244+
? new Map([[bashActivationEnvVarKey, getCommandAsString(bashActivation)]])
245+
: undefined;
246+
} else {
247+
return new Map([[bashActivationEnvVarKey, undefined]]);
248+
}
249+
}
250+
public readonly name: string = 'git-bash';
251+
}

src/features/terminal/startup/cmdStartup.ts

Whitespace-only changes.

src/features/terminal/startup/fishStartup.ts

Whitespace-only changes.

src/features/terminal/startup/nuShellStartup.ts

Whitespace-only changes.

src/managers/builtin/venvUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function getName(binPath: string): string {
111111
}
112112

113113
function pathForGitBash(binPath: string): string {
114-
return isWindows() ? binPath.replace(/\\/g, '/') : binPath;
114+
return isWindows() ? binPath.replace(/\\/g, '/').replace(/^([a-zA-Z]):/, '/$1') : binPath;
115115
}
116116

117117
async function getPythonInfo(env: NativeEnvInfo): Promise<PythonEnvironmentInfo> {

0 commit comments

Comments
 (0)