mirror of
https://github.com/desktop/desktop
synced 2024-10-02 14:23:59 +00:00
Refactor macOS shell integration and update docs
This commit is contained in:
parent
c96d12bc95
commit
bdb2195e49
|
@ -22,7 +22,7 @@ export function parse(label: string): Shell {
|
||||||
return parseEnumValue(Shell, label) ?? Default
|
return parseEnumValue(Shell, label) ?? Default
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBundleIDs(shell: Shell): string[] {
|
function getBundleIDs(shell: Shell): ReadonlyArray<string> {
|
||||||
switch (shell) {
|
switch (shell) {
|
||||||
case Shell.Terminal:
|
case Shell.Terminal:
|
||||||
return ['com.apple.Terminal']
|
return ['com.apple.Terminal']
|
||||||
|
@ -47,7 +47,7 @@ function getBundleIDs(shell: Shell): string[] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getShellPath(
|
async function getShellInfo(
|
||||||
shell: Shell
|
shell: Shell
|
||||||
): Promise<{ path: string; bundleID: string } | null> {
|
): Promise<{ path: string; bundleID: string } | null> {
|
||||||
const bundleIds = getBundleIDs(shell)
|
const bundleIds = getBundleIDs(shell)
|
||||||
|
@ -70,86 +70,86 @@ export async function getAvailableShells(): Promise<
|
||||||
ReadonlyArray<FoundShell<Shell>>
|
ReadonlyArray<FoundShell<Shell>>
|
||||||
> {
|
> {
|
||||||
const [
|
const [
|
||||||
terminalPath,
|
terminalInfo,
|
||||||
hyperPath,
|
hyperInfo,
|
||||||
iTermPath,
|
iTermInfo,
|
||||||
powerShellCorePath,
|
powerShellCoreInfo,
|
||||||
kittyPath,
|
kittyInfo,
|
||||||
alacrittyPath,
|
alacrittyInfo,
|
||||||
tabbyPath,
|
tabbyInfo,
|
||||||
wezTermPath,
|
wezTermInfo,
|
||||||
warpPath,
|
warpInfo,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
getShellPath(Shell.Terminal),
|
getShellInfo(Shell.Terminal),
|
||||||
getShellPath(Shell.Hyper),
|
getShellInfo(Shell.Hyper),
|
||||||
getShellPath(Shell.iTerm2),
|
getShellInfo(Shell.iTerm2),
|
||||||
getShellPath(Shell.PowerShellCore),
|
getShellInfo(Shell.PowerShellCore),
|
||||||
getShellPath(Shell.Kitty),
|
getShellInfo(Shell.Kitty),
|
||||||
getShellPath(Shell.Alacritty),
|
getShellInfo(Shell.Alacritty),
|
||||||
getShellPath(Shell.Tabby),
|
getShellInfo(Shell.Tabby),
|
||||||
getShellPath(Shell.WezTerm),
|
getShellInfo(Shell.WezTerm),
|
||||||
getShellPath(Shell.Warp),
|
getShellInfo(Shell.Warp),
|
||||||
])
|
])
|
||||||
|
|
||||||
const shells: Array<FoundShell<Shell>> = []
|
const shells: Array<FoundShell<Shell>> = []
|
||||||
if (terminalPath) {
|
if (terminalInfo) {
|
||||||
shells.push({ shell: Shell.Terminal, ...terminalPath })
|
shells.push({ shell: Shell.Terminal, ...terminalInfo })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hyperPath) {
|
if (hyperInfo) {
|
||||||
shells.push({ shell: Shell.Hyper, ...hyperPath })
|
shells.push({ shell: Shell.Hyper, ...hyperInfo })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iTermPath) {
|
if (iTermInfo) {
|
||||||
shells.push({ shell: Shell.iTerm2, ...iTermPath })
|
shells.push({ shell: Shell.iTerm2, ...iTermInfo })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (powerShellCorePath) {
|
if (powerShellCoreInfo) {
|
||||||
shells.push({ shell: Shell.PowerShellCore, ...powerShellCorePath })
|
shells.push({ shell: Shell.PowerShellCore, ...powerShellCoreInfo })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kittyPath) {
|
if (kittyInfo) {
|
||||||
const kittyExecutable = `${kittyPath.path}/Contents/MacOS/kitty`
|
const kittyExecutable = `${kittyInfo.path}/Contents/MacOS/kitty`
|
||||||
shells.push({
|
shells.push({
|
||||||
shell: Shell.Kitty,
|
shell: Shell.Kitty,
|
||||||
path: kittyExecutable,
|
path: kittyExecutable,
|
||||||
bundleID: kittyPath.bundleID,
|
bundleID: kittyInfo.bundleID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alacrittyPath) {
|
if (alacrittyInfo) {
|
||||||
const alacrittyExecutable = `${alacrittyPath.path}/Contents/MacOS/alacritty`
|
const alacrittyExecutable = `${alacrittyInfo.path}/Contents/MacOS/alacritty`
|
||||||
shells.push({
|
shells.push({
|
||||||
shell: Shell.Alacritty,
|
shell: Shell.Alacritty,
|
||||||
path: alacrittyExecutable,
|
path: alacrittyExecutable,
|
||||||
bundleID: alacrittyPath.bundleID,
|
bundleID: alacrittyInfo.bundleID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabbyPath) {
|
if (tabbyInfo) {
|
||||||
const tabbyExecutable = `${tabbyPath.path}/Contents/MacOS/Tabby`
|
const tabbyExecutable = `${tabbyInfo.path}/Contents/MacOS/Tabby`
|
||||||
shells.push({
|
shells.push({
|
||||||
shell: Shell.Tabby,
|
shell: Shell.Tabby,
|
||||||
path: tabbyExecutable,
|
path: tabbyExecutable,
|
||||||
bundleID: tabbyPath.bundleID,
|
bundleID: tabbyInfo.bundleID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wezTermPath) {
|
if (wezTermInfo) {
|
||||||
const wezTermExecutable = `${wezTermPath.path}/Contents/MacOS/wezterm`
|
const wezTermExecutable = `${wezTermInfo.path}/Contents/MacOS/wezterm`
|
||||||
shells.push({
|
shells.push({
|
||||||
shell: Shell.WezTerm,
|
shell: Shell.WezTerm,
|
||||||
path: wezTermExecutable,
|
path: wezTermExecutable,
|
||||||
bundleID: wezTermPath.bundleID,
|
bundleID: wezTermInfo.bundleID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (warpPath) {
|
if (warpInfo) {
|
||||||
const warpExecutable = `${warpPath.path}/Contents/MacOS/stable`
|
const warpExecutable = `${warpInfo.path}/Contents/MacOS/stable`
|
||||||
shells.push({
|
shells.push({
|
||||||
shell: Shell.Warp,
|
shell: Shell.Warp,
|
||||||
path: warpExecutable,
|
path: warpExecutable,
|
||||||
bundleID: warpPath.bundleID,
|
bundleID: warpInfo.bundleID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,8 +172,8 @@ use Hyper as a reference to explain the rest of the process.
|
||||||
|
|
||||||
### Step 1: Find the shell application
|
### Step 1: Find the shell application
|
||||||
|
|
||||||
The `getBundleID()s` function is used to map a shell enum to it's bundle ID
|
The `getBundleIDs()` function is used to map a shell enum to the possible bundle IDs
|
||||||
that is defined in it's manifest. You should add a new entry here for your
|
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.
|
shell. An array is returned to handle the case where a shell updates its bundle ID.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
@ -189,23 +189,23 @@ export async function getAvailableShells(): Promise<
|
||||||
ReadonlyArray<FoundShell<Shell>>
|
ReadonlyArray<FoundShell<Shell>>
|
||||||
> {
|
> {
|
||||||
const [
|
const [
|
||||||
terminalPath,
|
terminalInfo,
|
||||||
hyperPath,
|
hyperInfo,
|
||||||
iTermPath,
|
iTermInfo,
|
||||||
powerShellCorePath,
|
powerShellCoreInfo,
|
||||||
kittyPath,
|
kittyInfo,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
getShellPath(Shell.Terminal),
|
getShellInfo(Shell.Terminal),
|
||||||
getShellPath(Shell.Hyper),
|
getShellInfo(Shell.Hyper),
|
||||||
getShellPath(Shell.iTerm2),
|
getShellInfo(Shell.iTerm2),
|
||||||
getShellPath(Shell.PowerShellCore),
|
getShellInfo(Shell.PowerShellCore),
|
||||||
getShellPath(Shell.Kitty),
|
getShellInfo(Shell.Kitty),
|
||||||
])
|
])
|
||||||
|
|
||||||
// other code
|
// other code
|
||||||
|
|
||||||
if (hyperPath) {
|
if (hyperInfo) {
|
||||||
shells.push({ shell: Shell.Hyper, ...hyperPath })
|
shells.push({ shell: Shell.Hyper, ...hyperInfo })
|
||||||
}
|
}
|
||||||
|
|
||||||
// other code
|
// other code
|
||||||
|
|
Loading…
Reference in a new issue