diff --git a/src/renderer/api/terminal-api.ts b/src/renderer/api/terminal-api.ts index 165302c1ad..347dfac224 100644 --- a/src/renderer/api/terminal-api.ts +++ b/src/renderer/api/terminal-api.ts @@ -58,7 +58,7 @@ export class TerminalApi extends WebSocketApi { public onReady = new EventEmitter<[]>(); @observable public isReady = false; - @observable public rcFinished = false; + @observable public shellRunCommandsFinished = false; public readonly url: string; constructor(protected options: TerminalApiQuery) { @@ -92,7 +92,7 @@ export class TerminalApi extends WebSocketApi { connect() { this.emitStatus("Connecting ..."); this.onData.addListener(this._onReady, { prepend: true }); - this.onData.addListener(this._onRcReady); + this.onData.addListener(this._onShellRunCommandsFinished); super.connect(this.url); } @@ -109,14 +109,21 @@ export class TerminalApi extends WebSocketApi { this.onReady.removeAllListeners(); } - _onRcReady = (data: string) => { + _onShellRunCommandsFinished = (data: string) => { if (!data) { return; } - if (data.match(/\r?\n/) === null && data.endsWith(" ")) { - this.rcFinished = true; - this.onData.removeListener(this._onRcReady); + /** + * This is a heuistic for ditermining when a shell has finished executing + * its own rc file (or RunCommands file) such as `.bashrc` or `.zshrc`. + * + * This heuistic assumes that the prompt line of a terminal is a single line + * and ends with a whitespace character. + */ + if (data.match(/\r?\n/) === null && data.match(/\s$/)) { + this.shellRunCommandsFinished = true; + this.onData.removeListener(this._onShellRunCommandsFinished); } }; diff --git a/src/renderer/components/dock/terminal.store.ts b/src/renderer/components/dock/terminal.store.ts index 064b6aec31..dd5251bac2 100644 --- a/src/renderer/components/dock/terminal.store.ts +++ b/src/renderer/components/dock/terminal.store.ts @@ -117,21 +117,15 @@ export class TerminalStore extends Singleton { await when(() => this.connections.has(tab.id)); - const rcIsFinished = when(() => this.connections.get(tab.id).rcFinished); - const notifyLong = setTimeout(() => { - Notifications.info("Terminal shell is taking a long time to complete startup. Please check your .rc file.", { - timeout: 4_000, - }); - }, 2_500); + const rcIsFinished = when(() => this.connections.get(tab.id).shellRunCommandsFinished); const notifyVeryLong = setTimeout(() => { rcIsFinished.cancel(); - Notifications.info("Bypassing shell completion check.", { + Notifications.info("Terminal shell is taking a long time to complete startup. Please check your .rc file. Bypassing shell completion check.", { timeout: 4_000, }); - }, 7_500); + }, 10_000); await rcIsFinished.catch(noop); - clearTimeout(notifyLong); clearTimeout(notifyVeryLong); }