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 => {