Skip to content

Add kill-all option in interactive mode#89

Closed
phusi319 wants to merge 1 commit intosindresorhus:mainfrom
phusi319:kill-all
Closed

Add kill-all option in interactive mode#89
phusi319 wants to merge 1 commit intosindresorhus:mainfrom
phusi319:kill-all

Conversation

@phusi319
Copy link
Copy Markdown

Closes #21

Problem

When multiple processes share the same name (e.g. python, node), users have to run fkill repeatedly 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 9012

Selecting "Kill all" kills every matching process at once. Individual process selection continues to work exactly as before.

Design decisions

  • Minimal change: Only 12 lines added to interactive.js no new dependencies, no architectural changes
  • Only appears when useful: The option only shows when there's a search term AND 2+ matches. No risk of accidentally killing everything
  • Works with existing kill flow: Uses the same performKillSequence which already handles arrays of PIDs, including the force-kill fallback prompt
  • Consistent with maintainer guidance: @sindresorhus suggested a shortcut to "kill all with the same name" this surfaces that as a first-class search result option

Changes

  • interactive.js: Add "Kill all" option to search results when multiple processes match
  • cli.js: Document the feature in help text

Testing

  • All existing tests pass (xo && ava)
  • Zero new lint warnings

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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.js when 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);
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +268 to +269
name: `${chalk.red.bold('Kill all')} ${chalk.dim(`(${matchingProcesses.length} processes matching "${term}")`)}`,
value: matchingProcesses.map(process_ => process_.pid),
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
const choices = matchingProcesses.map(process_ => renderProcessForDisplay(process_, flags, memoryThreshold, cpuThreshold));

if (term && matchingProcesses.length > 1) {
choices.unshift({
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
choices.unshift({
choices.push({

Copilot uses AI. Check for mistakes.
@sindresorhus
Copy link
Copy Markdown
Owner

Sorry, not interested in fully AI generated PRs.

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.

Kill all

3 participants