Skip to content

feat: prompt confirmation on quit when terminal child processes are running - #675

Open
franckspike wants to merge 1 commit into
akinsho:mainfrom
franckspike:feat/confirm-quit-running-processes
Open

franckspike wants to merge 1 commit into
akinsho:mainfrom
franckspike:feat/confirm-quit-running-processes

Conversation

@franckspike

Copy link
Copy Markdown

Problem

When running long-lived background jobs (compilations, servers, watch tasks) inside a ToggleTerm terminal, quitting Neovim (:q, :qa, ZZ) abruptly terminates the shell and all running child processes without warning.

Solution

This PR adds an opt-in exit_protection feature:

  • Detects running child processes recursively under active terminal shells (using pgrep).
  • Skips intermediate/login shell processes (bash, zsh, fish, sh, etc.) so idle terminals never trigger false alerts.
  • Skips zombie / terminated processes.
  • Prompts for confirmation via vim.fn.confirm() listing affected terminals and running processes when attempting to quit.
  • Supports :q, :qa, :wq, :wqa, :x, :xa, and ZZ via safe abbreviations and mappings.
  • Forced commands with ! (:q!, :qa!, etc.) bypass the check.
  • Disabled by default (exit_protection.enabled = false) for complete backward compatibility.

Configuration

require("toggleterm").setup({
  exit_protection = {
    enabled = true,
    prompt_message = "Active processes detected in terminal. Really quit?",
    mapping = "ZZ",
    overwrite_commands = true,
  },
})

…unning

Add an opt-in exit_protection configuration option that checks for active child processes running inside terminals before quitting Neovim.

- Recursively inspect process tree under terminal root PID.
- Differentiate interactive shell processes (e.g. bash, zsh, fish) from actual command children so idle shells never block quit.
- Exclude zombie/dead processes.
- Add safe quit wrapper handling :q, :qa, :wq, :wqa, :x, :xa via cmdline abbreviations when enabled.
- Add configurable safe mapping (defaults to ZZ).
- Provide user commands ToggleTermSafeQuit, ToggleTermSafeQuitAll, ToggleTermSafeWriteQuit, ToggleTermSafeWriteQuitAll.
- Add unit tests for child process discovery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant