From 7d023b91b4fb7022311f4c119d3d9ce7f6a16ef9 Mon Sep 17 00:00:00 2001 From: Chapman Pendery <35637443+cpendery@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:49:52 -0700 Subject: [PATCH] feat: improve shell inference (#246) Signed-off-by: Chapman Pendery --- src/utils/shell.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/utils/shell.ts b/src/utils/shell.ts index 7d2d4da..2578924 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -58,6 +58,20 @@ export const setupZshDotfiles = async () => { }; export const inferShell = async () => { + // try getting shell from shell specific env variables + if (process.env.NU_VERSION != null) { + return Shell.Nushell; + } else if (process.env.XONSHRC != null) { + return Shell.Xonsh; + } else if (process.env.FISH_VERSION != null) { + return Shell.Fish; + } else if (process.env.ZSH_VERSION != null) { + return Shell.Zsh; + } else if (process.env.BASH_VERSION != null) { + return Shell.Bash; + } + + // try getting shell from env try { const name = path.parse(process.env.SHELL ?? "").name; const shellName = supportedShells.find((shell) => name.includes(shell)); @@ -65,6 +79,8 @@ export const inferShell = async () => { } catch { /* empty */ } + + // try getting shell from parent process const processResult = (await find("pid", process.ppid)).at(0); const name = processResult?.name; return name != null ? supportedShells.find((shell) => name.includes(shell)) : undefined;