From 2427d1776b9e996345c2112b4bbbff75c3e284bd Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Fri, 3 Jan 2025 12:52:37 -0500 Subject: [PATCH] fix: doctor from hanging when checking profile information if plugin is loaded Signed-off-by: Chapman Pendery --- src/runtime/alias.ts | 4 ++-- src/utils/shell.ts | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/runtime/alias.ts b/src/runtime/alias.ts index 7359ff6..4aacfe4 100644 --- a/src/runtime/alias.ts +++ b/src/runtime/alias.ts @@ -13,7 +13,7 @@ const executeShellCommand = await buildExecuteShellCommand(5_000); const loadBashAliases = async () => { const shellTarget = platform == "win32" ? await gitBashPath() : Shell.Bash; - const { stdout, stderr, status } = await executeShellCommand({ command: shellTarget, args: ["-i", "-c", "alias"], cwd: process.cwd() }); + const { stdout, stderr, status } = await executeShellCommand({ command: shellTarget, args: ["-i", "-c", "alias"], cwd: process.cwd(), env: { ISTERM: "1" } }); if (status !== 0) { log.debug({ msg: "failed to load bash aliases", stderr, status }); return; @@ -29,7 +29,7 @@ const loadBashAliases = async () => { }; const loadZshAliases = async () => { - const { stdout, stderr, status } = await executeShellCommand({ command: Shell.Zsh, args: ["-i", "-c", "alias"], cwd: process.cwd() }); + const { stdout, stderr, status } = await executeShellCommand({ command: Shell.Zsh, args: ["-i", "-c", "alias"], cwd: process.cwd(), env: { ISTERM: "1" } }); if (status !== 0) { log.debug({ msg: "failed to load zsh aliases", stderr, status }); return; diff --git a/src/utils/shell.ts b/src/utils/shell.ts index a14e173..12432d5 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -16,12 +16,10 @@ import log from "./log.js"; const exec = util.promisify(childProcess.exec); const safeExec = async (command: string, options?: childProcess.ExecOptions) => { + const defaultOptions: childProcess.ExecOptions = { timeout: 500, env: { ISTERM: "1" } }; try { - const { stdout, stderr } = await exec(command, options); - return { - stdout: typeof stdout === "string" ? stdout : stdout.toString(), - stderr: typeof stderr === "string" ? stderr : stderr.toString(), - }; + const { stdout, stderr } = await exec(command, { ...defaultOptions, ...options }); + return { stdout, stderr }; } catch (e) { log.debug({ msg: `error executing exec command: ${e}` }); return { stdout: undefined, stderr: undefined }; @@ -112,7 +110,7 @@ const getProfilePath = async (shell: Shell): Promise => { case Shell.Powershell: return (await safeExec(`echo $profile`, { shell })).stdout?.trim(); case Shell.Pwsh: - return (await safeExec(`echo $profile`, { shell })).stdout?.trim(); + return (await safeExec(`echo $profile`, { shell, timeout: 500, env: { ISTERM: "1" } })).stdout?.trim(); case Shell.Zsh: return path.join(os.homedir(), ".zshrc"); case Shell.Fish: @@ -120,7 +118,7 @@ const getProfilePath = async (shell: Shell): Promise => { case Shell.Xonsh: return path.join(os.homedir(), ".xonshrc"); case Shell.Nushell: - return (await safeExec(`echo $nu.env-path`, { shell })).stdout?.trim(); + return (await safeExec(`echo $nu.env-path`, { shell, timeout: 500, env: { ISTERM: "1" } })).stdout?.trim(); } };