diff --git a/README.md b/README.md index 8acaee9..200b6fa 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,12 @@ After completing the installation, you can run `is` to start the autocomplete se ### Usage -| Action | Command | -| ------------------------------------- | ------- | -| Start | `is` | -| Stop | `exit` | -| Check If Inside Inshellisense Session | `is -c` | +| Action | Command | Description | +| ------------------------------------- | --------------------------------- | ------------------------------------------------ | +| Start | `is` | Start inshellisense session on the current shell | +| Stop | `exit` | Stop inshellisense session on the current shell | +| Check If Inside Inshellisense Session | `is -c` | Check if shell inside inshellisense session | + #### Keybindings diff --git a/src/commands/root.ts b/src/commands/root.ts index 5e27637..3dfdd33 100644 --- a/src/commands/root.ts +++ b/src/commands/root.ts @@ -15,6 +15,7 @@ type RootCommandOptions = { verbose: boolean | undefined; check: boolean | undefined; test: boolean | undefined; + parentTermExit: boolean | undefined; }; export const action = (program: Command) => async (options: RootCommandOptions) => { @@ -40,5 +41,5 @@ export const action = (program: Command) => async (options: RootCommandOptions) } else if (shell == Shell.Bash) { await setupBashPreExec(); } - await render(shell, options.test ?? false); + await render(shell, options.test ?? false, options.parentTermExit ?? false); }; diff --git a/src/index.ts b/src/index.ts index 0d98a49..b10e866 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,6 +27,7 @@ program .action(action(program)) .option("-s, --shell ", `shell to use for command execution, supported shells: ${supportedShells}`) .option("-c, --check", `check if shell is in an inshellisense session`) + .option("--parent-term-exit", `when inshellisense is closed, kill the parent process`) .addOption(hiddenOption("-T, --test", "used to make e2e tests reproducible across machines")) .option("-V, --verbose", `enable verbose logging`) .showHelpAfterError("(add --help for additional information)"); diff --git a/src/ui/ui-root.ts b/src/ui/ui-root.ts index 18b2943..77e913c 100644 --- a/src/ui/ui-root.ts +++ b/src/ui/ui-root.ts @@ -16,7 +16,7 @@ export const renderConfirmation = (live: boolean): string => { return `inshellisense session [${statusMessage}]\n`; }; -export const render = async (shell: Shell, underTest: boolean) => { +export const render = async (shell: Shell, underTest: boolean, parentTermExit: boolean) => { const term = await isterm.spawn({ shell, rows: process.stdout.rows, cols: process.stdout.columns, underTest }); const suggestionManager = new SuggestionManager(term, shell); let hasActiveSuggestions = false; @@ -140,6 +140,9 @@ export const render = async (shell: Shell, underTest: boolean) => { }); term.onExit(({ exitCode }) => { + if (parentTermExit && process.ppid) { + process.kill(process.ppid); + } process.exit(exitCode); }); process.stdout.on("resize", () => {