From 6928eecb8feedaa3320210938e1f49f4d4625dfb Mon Sep 17 00:00:00 2001 From: Chapman Pendery <35637443+cpendery@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:44:21 -0800 Subject: [PATCH] feat: add cmd.exe support (#126) * feat: add cmd.exe support Signed-off-by: Chapman Pendery * fix: add template to logging failure Signed-off-by: Chapman Pendery --------- Signed-off-by: Chapman Pendery --- README.md | 1 + src/runtime/template.ts | 24 +++++++++++++++--------- src/utils/shell.ts | 11 ++++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 151c6b5..be2585f 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ inshellisense supports the following shells: - [fish](https://github.com/fish-shell/fish-shell) - [pwsh](https://github.com/PowerShell/PowerShell) - [powershell](https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-windows-powershell) (Windows Powershell) +- [cmd](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd) _(experimental)_ ## Contributing diff --git a/src/runtime/template.ts b/src/runtime/template.ts index 96cb0fa..f08d020 100644 --- a/src/runtime/template.ts +++ b/src/runtime/template.ts @@ -2,6 +2,7 @@ // Licensed under the MIT License. import fsAsync from "node:fs/promises"; +import log from "../utils/log.js"; const filepathsTemplate = async (cwd: string): Promise => { const files = await fsAsync.readdir(cwd, { withFileTypes: true }); @@ -28,15 +29,20 @@ export const runTemplates = async (template: Fig.TemplateStrings[] | Fig.Templat return ( await Promise.all( templates.map(async (t) => { - switch (t) { - case "filepaths": - return await filepathsTemplate(cwd); - case "folders": - return await foldersTemplate(cwd); - case "history": - return historyTemplate(); - case "help": - return helpTemplate(); + try { + switch (t) { + case "filepaths": + return await filepathsTemplate(cwd); + case "folders": + return await foldersTemplate(cwd); + case "history": + return historyTemplate(); + case "help": + return helpTemplate(); + } + } catch (e) { + log.debug({ msg: "template failed", e, template: t, cwd }); + return []; } }), ) diff --git a/src/utils/shell.ts b/src/utils/shell.ts index d78e944..cf9c0d8 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -19,9 +19,14 @@ export enum Shell { Cmd = "cmd", } -export const supportedShells = [Shell.Bash, process.platform == "win32" ? Shell.Powershell : null, Shell.Pwsh, Shell.Zsh, Shell.Fish].filter( - (shell) => shell != null, -) as Shell[]; +export const supportedShells = [ + Shell.Bash, + process.platform == "win32" ? Shell.Powershell : null, + Shell.Pwsh, + Shell.Zsh, + Shell.Fish, + process.platform == "win32" ? Shell.Cmd : null, +].filter((shell) => shell != null) as Shell[]; export const userZdotdir = process.env?.ZDOTDIR ?? os.homedir() ?? `~`; export const zdotdir = path.join(os.tmpdir(), `is-zsh`);