Skip to content

Commit

Permalink
feat: improve shell inference (#246)
Browse files Browse the repository at this point in the history
Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery authored Apr 25, 2024
1 parent 25ce5ca commit 7d023b9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,29 @@ 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));
if (shellName) return shellName;
} 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;
Expand Down

0 comments on commit 7d023b9

Please sign in to comment.