From bdb2195e4956fe5fa012cdcdbb6e44926c1af548 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sat, 9 Mar 2024 12:13:09 +1100 Subject: [PATCH] Refactor macOS shell integration and update docs --- app/src/lib/shells/darwin.ts | 86 ++++++++++++++--------------- docs/technical/shell-integration.md | 28 +++++----- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/app/src/lib/shells/darwin.ts b/app/src/lib/shells/darwin.ts index c370627b6c..3a0c4a7582 100644 --- a/app/src/lib/shells/darwin.ts +++ b/app/src/lib/shells/darwin.ts @@ -22,7 +22,7 @@ export function parse(label: string): Shell { return parseEnumValue(Shell, label) ?? Default } -function getBundleIDs(shell: Shell): string[] { +function getBundleIDs(shell: Shell): ReadonlyArray { switch (shell) { case Shell.Terminal: return ['com.apple.Terminal'] @@ -47,7 +47,7 @@ function getBundleIDs(shell: Shell): string[] { } } -async function getShellPath( +async function getShellInfo( shell: Shell ): Promise<{ path: string; bundleID: string } | null> { const bundleIds = getBundleIDs(shell) @@ -70,86 +70,86 @@ export async function getAvailableShells(): Promise< ReadonlyArray> > { const [ - terminalPath, - hyperPath, - iTermPath, - powerShellCorePath, - kittyPath, - alacrittyPath, - tabbyPath, - wezTermPath, - warpPath, + terminalInfo, + hyperInfo, + iTermInfo, + powerShellCoreInfo, + kittyInfo, + alacrittyInfo, + tabbyInfo, + wezTermInfo, + warpInfo, ] = await Promise.all([ - getShellPath(Shell.Terminal), - getShellPath(Shell.Hyper), - getShellPath(Shell.iTerm2), - getShellPath(Shell.PowerShellCore), - getShellPath(Shell.Kitty), - getShellPath(Shell.Alacritty), - getShellPath(Shell.Tabby), - getShellPath(Shell.WezTerm), - getShellPath(Shell.Warp), + getShellInfo(Shell.Terminal), + getShellInfo(Shell.Hyper), + getShellInfo(Shell.iTerm2), + getShellInfo(Shell.PowerShellCore), + getShellInfo(Shell.Kitty), + getShellInfo(Shell.Alacritty), + getShellInfo(Shell.Tabby), + getShellInfo(Shell.WezTerm), + getShellInfo(Shell.Warp), ]) const shells: Array> = [] - if (terminalPath) { - shells.push({ shell: Shell.Terminal, ...terminalPath }) + if (terminalInfo) { + shells.push({ shell: Shell.Terminal, ...terminalInfo }) } - if (hyperPath) { - shells.push({ shell: Shell.Hyper, ...hyperPath }) + if (hyperInfo) { + shells.push({ shell: Shell.Hyper, ...hyperInfo }) } - if (iTermPath) { - shells.push({ shell: Shell.iTerm2, ...iTermPath }) + if (iTermInfo) { + shells.push({ shell: Shell.iTerm2, ...iTermInfo }) } - if (powerShellCorePath) { - shells.push({ shell: Shell.PowerShellCore, ...powerShellCorePath }) + if (powerShellCoreInfo) { + shells.push({ shell: Shell.PowerShellCore, ...powerShellCoreInfo }) } - if (kittyPath) { - const kittyExecutable = `${kittyPath.path}/Contents/MacOS/kitty` + if (kittyInfo) { + const kittyExecutable = `${kittyInfo.path}/Contents/MacOS/kitty` shells.push({ shell: Shell.Kitty, path: kittyExecutable, - bundleID: kittyPath.bundleID, + bundleID: kittyInfo.bundleID, }) } - if (alacrittyPath) { - const alacrittyExecutable = `${alacrittyPath.path}/Contents/MacOS/alacritty` + if (alacrittyInfo) { + const alacrittyExecutable = `${alacrittyInfo.path}/Contents/MacOS/alacritty` shells.push({ shell: Shell.Alacritty, path: alacrittyExecutable, - bundleID: alacrittyPath.bundleID, + bundleID: alacrittyInfo.bundleID, }) } - if (tabbyPath) { - const tabbyExecutable = `${tabbyPath.path}/Contents/MacOS/Tabby` + if (tabbyInfo) { + const tabbyExecutable = `${tabbyInfo.path}/Contents/MacOS/Tabby` shells.push({ shell: Shell.Tabby, path: tabbyExecutable, - bundleID: tabbyPath.bundleID, + bundleID: tabbyInfo.bundleID, }) } - if (wezTermPath) { - const wezTermExecutable = `${wezTermPath.path}/Contents/MacOS/wezterm` + if (wezTermInfo) { + const wezTermExecutable = `${wezTermInfo.path}/Contents/MacOS/wezterm` shells.push({ shell: Shell.WezTerm, path: wezTermExecutable, - bundleID: wezTermPath.bundleID, + bundleID: wezTermInfo.bundleID, }) } - if (warpPath) { - const warpExecutable = `${warpPath.path}/Contents/MacOS/stable` + if (warpInfo) { + const warpExecutable = `${warpInfo.path}/Contents/MacOS/stable` shells.push({ shell: Shell.Warp, path: warpExecutable, - bundleID: warpPath.bundleID, + bundleID: warpInfo.bundleID, }) } diff --git a/docs/technical/shell-integration.md b/docs/technical/shell-integration.md index ce2e5a46a5..14c6c16160 100644 --- a/docs/technical/shell-integration.md +++ b/docs/technical/shell-integration.md @@ -172,8 +172,8 @@ use Hyper as a reference to explain the rest of the process. ### Step 1: Find the shell application -The `getBundleID()s` function is used to map a shell enum to it's bundle ID -that is defined in it's manifest. You should add a new entry here for your +The `getBundleIDs()` function is used to map a shell enum to the possible bundle IDs +that are defined in its manifest. You should add a new entry here for your shell. An array is returned to handle the case where a shell updates its bundle ID. ```ts @@ -189,23 +189,23 @@ export async function getAvailableShells(): Promise< ReadonlyArray> > { const [ - terminalPath, - hyperPath, - iTermPath, - powerShellCorePath, - kittyPath, + terminalInfo, + hyperInfo, + iTermInfo, + powerShellCoreInfo, + kittyInfo, ] = await Promise.all([ - getShellPath(Shell.Terminal), - getShellPath(Shell.Hyper), - getShellPath(Shell.iTerm2), - getShellPath(Shell.PowerShellCore), - getShellPath(Shell.Kitty), + getShellInfo(Shell.Terminal), + getShellInfo(Shell.Hyper), + getShellInfo(Shell.iTerm2), + getShellInfo(Shell.PowerShellCore), + getShellInfo(Shell.Kitty), ]) // other code - if (hyperPath) { - shells.push({ shell: Shell.Hyper, ...hyperPath }) + if (hyperInfo) { + shells.push({ shell: Shell.Hyper, ...hyperInfo }) } // other code