UNPKG

detect-shells

Version:

Detect shells installed on a system

155 lines (154 loc) 6.03 kB
"use strict"; // automatically generated by scripts/fetch-shells.mjs // do not edit this file directly. Object.defineProperty(exports, "__esModule", { value: true }); exports.launch = exports.getAvailableShells = exports.parse = exports.Default = exports.Shell = void 0; const child_process_1 = require("child_process"); const fatal_error_1 = require("../fatal-error"); const enum_1 = require("../enum"); const path_exists_1 = require("../path-exists"); var Shell; (function (Shell) { Shell["Gnome"] = "GNOME Terminal"; Shell["Mate"] = "MATE Terminal"; Shell["Tilix"] = "Tilix"; Shell["Terminator"] = "Terminator"; Shell["Urxvt"] = "URxvt"; Shell["Konsole"] = "Konsole"; Shell["Xterm"] = "XTerm"; Shell["Terminology"] = "Terminology"; Shell["Deepin"] = "Deepin Terminal"; Shell["Elementary"] = "Elementary Terminal"; Shell["XFCE"] = "XFCE Terminal"; Shell["Alacritty"] = "Alacritty"; Shell["Kitty"] = "Kitty"; })(Shell = exports.Shell || (exports.Shell = {})); exports.Default = Shell.Gnome; function parse(label) { var _a; return (_a = (0, enum_1.parseEnumValue)(Shell, label)) !== null && _a !== void 0 ? _a : exports.Default; } exports.parse = parse; async function getPathIfAvailable(path) { return (await (0, path_exists_1.pathExists)(path)) ? path : null; } function getShellPath(shell) { switch (shell) { case Shell.Gnome: return getPathIfAvailable('/usr/bin/gnome-terminal'); case Shell.Mate: return getPathIfAvailable('/usr/bin/mate-terminal'); case Shell.Tilix: return getPathIfAvailable('/usr/bin/tilix'); case Shell.Terminator: return getPathIfAvailable('/usr/bin/terminator'); case Shell.Urxvt: return getPathIfAvailable('/usr/bin/urxvt'); case Shell.Konsole: return getPathIfAvailable('/usr/bin/konsole'); case Shell.Xterm: return getPathIfAvailable('/usr/bin/xterm'); case Shell.Terminology: return getPathIfAvailable('/usr/bin/terminology'); case Shell.Deepin: return getPathIfAvailable('/usr/bin/deepin-terminal'); case Shell.Elementary: return getPathIfAvailable('/usr/bin/io.elementary.terminal'); case Shell.XFCE: return getPathIfAvailable('/usr/bin/xfce4-terminal'); case Shell.Alacritty: return getPathIfAvailable('/usr/bin/alacritty'); case Shell.Kitty: return getPathIfAvailable('/usr/bin/kitty'); default: return (0, fatal_error_1.assertNever)(shell, `Unknown shell: ${shell}`); } } async function getAvailableShells() { const [gnomeTerminalPath, mateTerminalPath, tilixPath, terminatorPath, urxvtPath, konsolePath, xtermPath, terminologyPath, deepinPath, elementaryPath, xfcePath, alacrittyPath, kittyPath,] = await Promise.all([ getShellPath(Shell.Gnome), getShellPath(Shell.Mate), getShellPath(Shell.Tilix), getShellPath(Shell.Terminator), getShellPath(Shell.Urxvt), getShellPath(Shell.Konsole), getShellPath(Shell.Xterm), getShellPath(Shell.Terminology), getShellPath(Shell.Deepin), getShellPath(Shell.Elementary), getShellPath(Shell.XFCE), getShellPath(Shell.Alacritty), getShellPath(Shell.Kitty), ]); const shells = []; if (gnomeTerminalPath) { shells.push({ shell: Shell.Gnome, path: gnomeTerminalPath }); } if (mateTerminalPath) { shells.push({ shell: Shell.Mate, path: mateTerminalPath }); } if (tilixPath) { shells.push({ shell: Shell.Tilix, path: tilixPath }); } if (terminatorPath) { shells.push({ shell: Shell.Terminator, path: terminatorPath }); } if (urxvtPath) { shells.push({ shell: Shell.Urxvt, path: urxvtPath }); } if (konsolePath) { shells.push({ shell: Shell.Konsole, path: konsolePath }); } if (xtermPath) { shells.push({ shell: Shell.Xterm, path: xtermPath }); } if (terminologyPath) { shells.push({ shell: Shell.Terminology, path: terminologyPath }); } if (deepinPath) { shells.push({ shell: Shell.Deepin, path: deepinPath }); } if (elementaryPath) { shells.push({ shell: Shell.Elementary, path: elementaryPath }); } if (xfcePath) { shells.push({ shell: Shell.XFCE, path: xfcePath }); } if (alacrittyPath) { shells.push({ shell: Shell.Alacritty, path: alacrittyPath }); } if (kittyPath) { shells.push({ shell: Shell.Kitty, path: kittyPath }); } return shells; } exports.getAvailableShells = getAvailableShells; function launch(foundShell, path) { const shell = foundShell.shell; switch (shell) { case Shell.Gnome: case Shell.Mate: case Shell.Tilix: case Shell.Terminator: case Shell.XFCE: case Shell.Alacritty: return (0, child_process_1.spawn)(foundShell.path, ['--working-directory', path]); case Shell.Urxvt: return (0, child_process_1.spawn)(foundShell.path, ['-cd', path]); case Shell.Konsole: return (0, child_process_1.spawn)(foundShell.path, ['--workdir', path]); case Shell.Xterm: return (0, child_process_1.spawn)(foundShell.path, ['-e', '/bin/bash'], { cwd: path }); case Shell.Terminology: return (0, child_process_1.spawn)(foundShell.path, ['-d', path]); case Shell.Deepin: return (0, child_process_1.spawn)(foundShell.path, ['-w', path]); case Shell.Elementary: return (0, child_process_1.spawn)(foundShell.path, ['-w', path]); case Shell.Kitty: return (0, child_process_1.spawn)(foundShell.path, ['--single-instance', '--directory', path]); default: return (0, fatal_error_1.assertNever)(shell, `Unknown shell: ${shell}`); } } exports.launch = launch;