diff --git a/src/ui/ui-doctor.ts b/src/ui/ui-doctor.ts index 9e87d23..4ad33a9 100644 --- a/src/ui/ui-doctor.ts +++ b/src/ui/ui-doctor.ts @@ -2,11 +2,12 @@ // Licensed under the MIT License. import chalk from "chalk"; -import { checkLegacyConfigs, checkShellConfigs } from "../utils/shell.js"; +import { checkLegacyConfigs, checkShellConfigPlugin, checkShellConfigs } from "../utils/shell.js"; export const render = async () => { let errors = 0; errors += await renderLegacyConfigIssues(); + errors += await renderShellPluginIssues(); errors += renderShellConfigIssues(); process.exit(errors); @@ -44,3 +45,31 @@ const renderShellConfigIssues = (): number => { } return 0; }; + +const renderShellPluginIssues = async (): Promise => { + const { shellsWithoutPlugin, shellsWithBadPlugin } = await checkShellConfigPlugin(); + if (shellsWithoutPlugin.length == 0) { + process.stdout.write(chalk.green("✓") + " all shells have plugins\n"); + } else { + process.stderr.write(chalk.red("•") + " the following shells do not have the plugin installed:\n"); + shellsWithoutPlugin.forEach((shell) => { + process.stderr.write(chalk.red(" - ") + shell + "\n"); + }); + process.stderr.write(chalk.yellow(" review the README to generate the missing shell plugins, this warning can be ignored if you prefer manual startup\n")); + } + + if (shellsWithBadPlugin.length == 0) { + process.stdout.write(chalk.green("✓") + " all shells have correct plugins\n"); + } else { + process.stderr.write(chalk.red("•") + " the following shells have plugins incorrectly installed:\n"); + shellsWithBadPlugin.forEach((shell) => { + process.stderr.write(chalk.red(" - ") + shell + "\n"); + }); + process.stderr.write(chalk.yellow(" remove and regenerate the plugins according to the README, only whitespace can be after the shell plugins\n")); + } + + if (shellsWithoutPlugin.length > 0 || shellsWithBadPlugin.length > 0) { + return 1; + } + return 0; +}; diff --git a/src/utils/shell.ts b/src/utils/shell.ts index b94f845..a14e173 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -84,6 +84,27 @@ export const checkLegacyConfigs = async (): Promise => { return shellsWithLegacyConfig; }; +export const checkShellConfigPlugin = async () => { + const shellsWithoutPlugin: Shell[] = []; + const shellsWithBadPlugin: Shell[] = []; + for (const shell of supportedShells) { + const profilePath = await getProfilePath(shell); + if (profilePath != null && fs.existsSync(profilePath)) { + const profile = await fsAsync.readFile(profilePath, "utf8"); + + const profileContainsSource = profile.includes(getShellSourceCommand(shell)); + const profileEndsWithSource = profile.trimEnd().endsWith(getShellSourceCommand(shell)); + + if (!profileContainsSource) { + shellsWithoutPlugin.push(shell); + } else if (!profileEndsWithSource) { + shellsWithBadPlugin.push(shell); + } + } + } + return { shellsWithoutPlugin, shellsWithBadPlugin }; +}; + const getProfilePath = async (shell: Shell): Promise => { switch (shell) { case Shell.Bash: