Skip to content

Commit 7bf1e35

Browse files
authored
feat: support env and cwd in shell api (#52)
1 parent 64abff8 commit 7bf1e35

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/shells.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export type ShellCreateOpts = {
1818
export type ShellRunOpts = {
1919
ptySize?: ShellSize;
2020
shellName?: string;
21+
env?: Record<string, string>;
22+
cwd?: string;
2123
};
2224
export type ShellOpenOpts = {
2325
ptySize?: ShellSize;
@@ -123,8 +125,9 @@ export class Shells extends Disposable {
123125
command,
124126
opts?.ptySize ?? DEFAULT_SHELL_SIZE,
125127
undefined,
126-
undefined,
127-
opts?.shellName
128+
opts?.env,
129+
opts?.shellName,
130+
opts?.cwd
128131
);
129132

130133
return shell;
@@ -287,7 +290,8 @@ function runCommandAsUser(
287290
shellSize: ShellSize = DEFAULT_SHELL_SIZE,
288291
runPreCommand?: () => Promise<void>,
289292
env?: Record<string, string>,
290-
shellName?: string
293+
shellName?: string,
294+
cwd?: string
291295
): RunningCommand {
292296
const disposableStore = new DisposableStore();
293297
const onOutput = new Emitter<string>();
@@ -300,10 +304,15 @@ function runCommandAsUser(
300304
await runPreCommand();
301305
}
302306

303-
const commandWithEnv = `env ${Object.entries(env ?? {})
307+
// TODO: use a new shell API that natively supports cwd & env
308+
let commandWithEnv = `env ${Object.entries(env ?? {})
304309
.map(([key, value]) => `${key}=${value}`)
305310
.join(" ")} ${command}`;
306311

312+
if (cwd) {
313+
commandWithEnv = `cd ${cwd} && ${commandWithEnv}`;
314+
}
315+
307316
shell = await pitcher.clients.shell.create(
308317
pitcher.workspacePath,
309318
shellSize,

0 commit comments

Comments
 (0)