1
0
mirror of https://github.com/desktop/desktop synced 2024-07-02 15:48:39 +00:00

Refactor macOS shell integration and update docs

This commit is contained in:
Lucas 2024-03-09 12:13:09 +11:00
parent c96d12bc95
commit bdb2195e49
No known key found for this signature in database
GPG Key ID: E6CAEAA74B3C53AC
2 changed files with 57 additions and 57 deletions

View File

@ -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<string> {
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<FoundShell<Shell>>
> {
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<FoundShell<Shell>> = []
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,
})
}

View File

@ -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<FoundShell<Shell>>
> {
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