From 9bdc6597965bda4c2511bb14df1c683c6403c345 Mon Sep 17 00:00:00 2001 From: Chapman Pendery <35637443+cpendery@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:51:45 -0800 Subject: [PATCH] fix: failing config extraction for powershell in MacOS/Linux (#29) * fix: failing config extraction for powershell in MacOS/Linux Signed-off-by: Chapman Pendery * fix: prevent invocation of powershell on unix systems Signed-off-by: Chapman Pendery --------- Signed-off-by: Chapman Pendery --- src/utils/bindings.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/utils/bindings.ts b/src/utils/bindings.ts index 50d5cc0..8aa8c25 100644 --- a/src/utils/bindings.ts +++ b/src/utils/bindings.ts @@ -50,13 +50,31 @@ const pwshScriptCommand = (): string => { }; const pwshConfigPath = async (): Promise => { - const { stdout } = await execAsync("echo $profile", { shell: "pwsh" }); - return stdout.trim(); + try { + const { stdout } = await execAsync("echo $profile", { shell: "pwsh" }); + return stdout.trim(); + } catch { + /* empty */ + } + switch (process.platform) { + case "win32": + return path.join(os.homedir(), "Documents", "Powershell", "Microsoft.PowerShell_profile.ps1"); + case "linux": + case "darwin": + return path.join(os.homedir(), ".config", "powershell", "Microsoft.PowerShell_profile.ps1"); + default: + throw new Error("Unsupported platform"); + } }; const powershellConfigPath = async (): Promise => { - const { stdout } = await execAsync("echo $profile", { shell: "powershell" }); - return stdout.trim(); + try { + const { stdout } = await execAsync("echo $profile", { shell: "powershell" }); + return stdout.trim(); + } catch { + /* empty */ + } + return path.join(os.homedir(), "Documents", "WindowsPowershell", "Microsoft.PowerShell_profile.ps1"); }; export const availableBindings = async (): Promise => { @@ -96,8 +114,8 @@ export const availableBindings = async (): Promise => { } } - const powershellResolvedConfigPath = await powershellConfigPath(); if (process.platform == "win32") { + const powershellResolvedConfigPath = await powershellConfigPath(); if (!fs.existsSync(powershellResolvedConfigPath)) { bindings.push(Shell.Powershell); } else {