Add kill-all option in interactive mode#89
Add kill-all option in interactive mode#89phusi319 wants to merge 1 commit intosindresorhus:mainfrom
Conversation
When searching in interactive mode with multiple matching processes, a 'Kill all' option now appears at the top of the results list. Selecting it kills all matching processes at once. This eliminates the need to run fkill repeatedly when multiple processes share the same name (e.g., python, node). Closes sindresorhus#21
There was a problem hiding this comment.
Pull request overview
Adds a “Kill all” choice to the interactive search results so users can terminate all processes matching a search term in one action (addressing #21).
Changes:
- Add a synthetic “Kill all” choice in
interactive.jswhen a search term yields 2+ matches, returning an array of PIDs to the existing kill flow. - Document the new interactive behavior in the CLI help text.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| interactive.js | Injects a “Kill all” option into interactive search choices and passes either a PID or PID array into the kill sequence. |
| cli.js | Updates help text to mention the new interactive “Kill all” capability. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }); | ||
|
|
||
| performKillSequence(selectedPid); | ||
| performKillSequence(selectedValue); |
There was a problem hiding this comment.
performKillSequence is async but is called without await here. If the forced-kill path throws (or any other rejection bubbles up), this can become an unhandled promise rejection. Consider awaiting it and handling any errors (for example, by catching and exiting with a non-zero code / showing a message) so failures don’t get lost.
| name: `${chalk.red.bold('Kill all')} ${chalk.dim(`(${matchingProcesses.length} processes matching "${term}")`)}`, | ||
| value: matchingProcesses.map(process_ => process_.pid), |
There was a problem hiding this comment.
The display string wraps the search term in double quotes. If the user enters a term containing " or control characters, the rendered label can become confusing or misleading in the UI. Consider escaping/quoting the term more robustly (or using single quotes) before interpolating it into the prompt label.
| const choices = matchingProcesses.map(process_ => renderProcessForDisplay(process_, flags, memoryThreshold, cpuThreshold)); | ||
|
|
||
| if (term && matchingProcesses.length > 1) { | ||
| choices.unshift({ |
There was a problem hiding this comment.
Placing the “Kill all” choice at the top (unshift) makes it the default/first result for any multi-match search, which increases the chance of accidentally killing all matching processes when the user presses Enter after typing a term. Consider adding an extra confirmation step when this option is chosen, or move it below the individual process results so it’s not the first selectable item.
| choices.unshift({ | |
| choices.push({ |
|
Sorry, not interested in fully AI generated PRs. |
Closes #21
Problem
When multiple processes share the same name (e.g.
python,node), users have to runfkillrepeatedly to kill each one individually. This was the most requested enhancement (funded \ on IssueHunt).Solution
When searching in interactive mode, if 2 or more processes match the search term, a "Kill all" option appears at the top of the results list:
? Running processes: python Kill all (3 processes matching "python") python 1234 python 5678 python 9012Selecting "Kill all" kills every matching process at once. Individual process selection continues to work exactly as before.
Design decisions
interactive.jsno new dependencies, no architectural changesperformKillSequencewhich already handles arrays of PIDs, including the force-kill fallback promptChanges
interactive.js: Add "Kill all" option to search results when multiple processes matchcli.js: Document the feature in help textTesting
xo && ava)