From ec065784ec34eaa5978658b28a9c66be8e450226 Mon Sep 17 00:00:00 2001 From: Phu Si On Date: Fri, 27 Mar 2026 18:20:02 +0200 Subject: [PATCH] Add kill-all option in interactive mode 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 #21 --- cli.js | 3 +++ interactive.js | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cli.js b/cli.js index e65d553..d8d7b3f 100755 --- a/cli.js +++ b/cli.js @@ -28,6 +28,9 @@ const cli = meow(` In interactive mode, 🚦n% indicates high CPU usage and 🐏n% indicates high memory usage. Supports fuzzy search in the interactive mode. + When multiple processes match your search, a "Kill all" option appears + to kill all matching processes at once. + The process name is case-insensitive by default. `, { importMeta: import.meta, diff --git a/interactive.js b/interactive.js index 4983d8d..c3a44a9 100644 --- a/interactive.js +++ b/interactive.js @@ -256,16 +256,25 @@ const listProcesses = async (processes, flags) => { const cpuThreshold = flags.verbose ? 0 : 3; const searcher = new FuzzySearch(processes, ['name'], {caseSensitive: false}); - const selectedPid = await search({ + const selectedValue = await search({ message: 'Running processes:', pageSize: 10, async source(term = '') { const matchingProcesses = filterAndSortProcesses(processes, term, searcher, flags); - return matchingProcesses.map(process_ => renderProcessForDisplay(process_, flags, memoryThreshold, cpuThreshold)); + const choices = matchingProcesses.map(process_ => renderProcessForDisplay(process_, flags, memoryThreshold, cpuThreshold)); + + if (term && matchingProcesses.length > 1) { + choices.unshift({ + name: `${chalk.red.bold('Kill all')} ${chalk.dim(`(${matchingProcesses.length} processes matching "${term}")`)}`, + value: matchingProcesses.map(process_ => process_.pid), + }); + } + + return choices; }, }); - performKillSequence(selectedPid); + performKillSequence(selectedValue); }; const init = async flags => {