@@ -9,6 +9,7 @@ import cliTruncate from 'cli-truncate';
99import { allPortsWithPid } from 'pid-port' ;
1010import fkill from 'fkill' ;
1111import processExists from 'process-exists' ;
12+ import FuzzySearch from 'fuzzy-search' ;
1213
1314const isWindows = process . platform === 'win32' ;
1415const commandLineMargins = 4 ;
@@ -43,16 +44,6 @@ const processExited = async (pid, timeout) => {
4344 return ! exists ;
4445} ;
4546
46- const nameFilter = ( input , process_ ) => {
47- const isPort = input [ 0 ] === ':' ;
48-
49- if ( isPort ) {
50- return process_ . ports . find ( port => port . startsWith ( input . slice ( 1 ) ) ) ;
51- }
52-
53- return process_ . name . toLowerCase ( ) . includes ( input . toLowerCase ( ) ) ;
54- } ;
55-
5647const preferNotMatching = matches => ( a , b ) => {
5748 const aMatches = matches ( a ) ;
5849 return matches ( b ) === aMatches ? 0 : ( aMatches ? 1 : - 1 ) ;
@@ -99,22 +90,24 @@ const preferHeurisicallyInterestingProcesses = (a, b) => {
9990} ;
10091
10192const filterProcesses = ( input , processes , flags ) => {
102- const filters = {
103- name : process_ => input ? nameFilter ( input , process_ ) : true ,
104- verbose : process_ => input ? ( isWindows ? process_ . name : process_ . cmd ) . toLowerCase ( ) . includes ( input . toLowerCase ( ) ) : true ,
105- } ;
106-
10793 const memoryThreshold = flags . verbose ? 0 : 1 ;
10894 const cpuThreshold = flags . verbose ? 0 : 3 ;
10995
110- return processes
96+ const filteredProcesses = new FuzzySearch (
97+ processes ,
98+ [ flags . verbose && ! isWindows ? 'cmd' : 'name' ] ,
99+ {
100+ caseSensitive : false ,
101+ } ,
102+ )
103+ . search ( input ) ;
104+
105+ return filteredProcesses
111106 . filter ( process_ => ! (
112107 process_ . name . endsWith ( '-helper' )
113108 || process_ . name . endsWith ( 'Helper' )
114109 || process_ . name . endsWith ( 'HelperApp' )
115110 ) )
116- // eslint-disable-next-line unicorn/no-array-callback-reference
117- . filter ( flags . verbose ? filters . verbose : filters . name )
118111 . sort ( preferHeurisicallyInterestingProcesses )
119112 . map ( process_ => {
120113 const renderPercentage = percents => {
0 commit comments