Skip to content

Commit

Permalink
feat: add cmd.exe support (#126)
Browse files Browse the repository at this point in the history
* feat: add cmd.exe support

Signed-off-by: Chapman Pendery <[email protected]>

* fix: add template to logging failure

Signed-off-by: Chapman Pendery <[email protected]>

---------

Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery authored Dec 14, 2023
1 parent dded563 commit 6928eec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 15 additions & 9 deletions src/runtime/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fig.Suggestion[]> => {
const files = await fsAsync.readdir(cwd, { withFileTypes: true });
Expand All @@ -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 [];
}
}),
)
Expand Down
11 changes: 8 additions & 3 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down

0 comments on commit 6928eec

Please sign in to comment.