Skip to content

Commit 8d9ca12

Browse files
chore: use refined PS1
1 parent d5bf781 commit 8d9ca12

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/services/terminal.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export class TerminalService {
125125

126126
const shell = this.resolveShell(isHost);
127127
const cwd = this.resolveCwd(isHost);
128-
const env = this.buildSafeEnv();
128+
const ps1 = this.resolvePs1(shell, isHost);
129+
const env = this.buildSafeEnv(ps1);
129130
const args = isHost ? ['-t', '1', '-m', '-u', '-i', '-n', shell, '-i'] : ['-i'];
130131

131132
try {
@@ -216,11 +217,12 @@ export class TerminalService {
216217
return '/root';
217218
}
218219

219-
private buildSafeEnv(): NodeJS.ProcessEnv {
220+
private buildSafeEnv(ps1?: string): NodeJS.ProcessEnv {
220221
return {
221222
...process.env,
222223
TERM: 'xterm-256color',
223-
COLORTERM: 'truecolor'
224+
COLORTERM: 'truecolor',
225+
...(ps1 ? { PS1: ps1 } : {})
224226
};
225227
}
226228

@@ -232,4 +234,16 @@ export class TerminalService {
232234
return 'http://localhost:5000';
233235
}
234236
}
237+
238+
private resolvePs1(shell: string, isHostShell: boolean): string | undefined {
239+
const isBash = shell.includes('bash') || isHostShell;
240+
241+
if (isBash) {
242+
// Bash (supports \[ \])
243+
return '\\[\\x1b[1;32m\\]\\u@\\h\\[\\x1b[0m\\]:\\[\\x1b[1;34m\\]\\w\\[\\x1b[0m\\]\\$ ';
244+
}
245+
246+
// sh / ash fallback (no \[ \])
247+
return '\\x1b[1;32m\\u@\\h\\x1b[0m:\\x1b[1;34m\\w\\x1b[0m\\$ ';
248+
}
235249
}

0 commit comments

Comments
 (0)