fix: shell inference when ENV:SHELL isn't set & add back option for user to supply shell (#93)

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Chapman Pendery
2023-11-27 13:18:51 -05:00
committed by GitHub
parent e8c752bada
commit ba58fc5706
3 changed files with 11 additions and 4 deletions
+6 -2
View File
@@ -9,10 +9,14 @@ import { Command } from "commander";
export const supportedShells = shells.join(", ");
export const action = (program: Command) => async () => {
type RootCommandOptions = {
shell: Shell | undefined;
};
export const action = (program: Command) => async (options: RootCommandOptions) => {
await loadConfig(program);
const shell = (await inferShell()) as unknown as Shell | undefined;
const shell = options.shell ?? ((await inferShell()) as unknown as Shell | undefined);
if (shell == null) {
program.error(`Unable to identify shell, use the -s/--shell option to provide your shell`, { exitCode: 1 });
}
+2 -1
View File
@@ -9,7 +9,7 @@ import { Command } from "commander";
import bind from "./commands/bind.js";
import uninstall from "./commands/uninstall.js";
import { action } from "./commands/root.js";
import { action, supportedShells } from "./commands/root.js";
import { getVersion } from "./utils/version.js";
const program = new Command();
@@ -19,6 +19,7 @@ program
.description("IDE style command line auto complete")
.version(await getVersion(), "-v, --version", "output the current version")
.action(action(program))
.option("-s, --shell <shell>", `shell to use for command execution, supported shells: ${supportedShells}`)
.showHelpAfterError("(add --help for additional information)");
program.addCommand(bind);
+3 -1
View File
@@ -10,7 +10,9 @@ import fs from "node:fs";
export const inferShell = async () => {
try {
return path.parse(process.env.SHELL ?? "").name;
const name = path.parse(process.env.SHELL ?? "").name;
const shellName = supportedShells.find((shell) => name.includes(shell));
if (shellName) return shellName;
} catch {
/* empty */
}