Skip to content

Commit

Permalink
fix: doctor from hanging when checking profile information if plugin …
Browse files Browse the repository at this point in the history
…is loaded (#317)

Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery authored Jan 3, 2025
1 parent a0d3857 commit 82fa293
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/runtime/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -112,15 +110,15 @@ const getProfilePath = async (shell: Shell): Promise<string | undefined> => {
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:
return path.join(os.homedir(), ".config", "fish", "config.fish");
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();
}
};

Expand Down

0 comments on commit 82fa293

Please sign in to comment.