@@ -121,32 +121,37 @@ const searchProcessesByPort = (processes, port) => processes.filter(process_ =>
121121
122122const searchProcessByPid = ( processes , pid ) => processes . find ( process_ => String ( process_ . pid ) === pid ) ;
123123
124- const searchProcessesByName = ( processes , term , searcher ) => {
125- const lowerTerm = term . toLowerCase ( ) ;
124+ const searchProcessesByName = ( processes , term , searcher , flags = { } ) => {
125+ // Determine if we should match case-sensitively
126+ const hasUpperCase = / [ A - Z ] / . test ( term ) ;
127+ const shouldMatchCase = flags . caseSensitive || ( flags . smartCase && hasUpperCase ) ;
128+
129+ const normalizedTerm = shouldMatchCase ? term : term . toLowerCase ( ) ;
126130 const exactMatches = [ ] ;
127131 const startsWithMatches = [ ] ;
128132 const containsMatches = [ ] ;
129133
130134 for ( const process_ of processes ) {
131- const lowerName = process_ . name . toLowerCase ( ) ;
132- if ( lowerName === lowerTerm ) {
135+ const normalizedName = shouldMatchCase ? process_ . name : process_ . name . toLowerCase ( ) ;
136+ if ( normalizedName === normalizedTerm ) {
133137 exactMatches . push ( process_ ) ;
134- } else if ( lowerName . startsWith ( lowerTerm ) ) {
138+ } else if ( normalizedName . startsWith ( normalizedTerm ) ) {
135139 startsWithMatches . push ( process_ ) ;
136- } else if ( lowerName . includes ( lowerTerm ) ) {
140+ } else if ( normalizedName . includes ( normalizedTerm ) ) {
137141 containsMatches . push ( process_ ) ;
138142 }
139143 }
140144
141145 // Fuzzy matches (excluding all exact/starts/contains matches)
146+ // Keep fuzzy search case-insensitive for better UX
142147 const matchedPids = new Set ( [ ...exactMatches , ...startsWithMatches , ...containsMatches ] . map ( process_ => process_ . pid ) ) ;
143148 const fuzzyResults = searcher . search ( term ) . filter ( process_ => ! matchedPids . has ( process_ . pid ) ) ;
144149
145150 // Combine in priority order
146151 return [ ...exactMatches , ...startsWithMatches , ...containsMatches , ...fuzzyResults ] ;
147152} ;
148153
149- const filterAndSortProcesses = ( processes , term , searcher ) => {
154+ const filterAndSortProcesses = ( processes , term , searcher , flags ) => {
150155 const filtered = processes . filter ( process_ => ! isHelperProcess ( process_ ) ) ;
151156
152157 // No search term: show all sorted by performance
@@ -167,16 +172,21 @@ const filterAndSortProcesses = (processes, term, searcher) => {
167172 }
168173
169174 // Search by name
170- return searchProcessesByName ( filtered , term , searcher ) ;
175+ return searchProcessesByName ( filtered , term , searcher , flags ) ;
171176} ;
172177
173- const handleFkillError = async processes => {
174- const shouldForceKill = await promptForceKill ( processes , 'Error killing process.' ) ;
178+ const handleFkillError = async ( inputs , flags = { } ) => {
179+ const shouldForceKill = await promptForceKill ( inputs , 'Error killing process.' ) ;
175180
176181 if ( shouldForceKill ) {
177- await fkill ( processes , {
182+ // Determine case sensitivity based on flags and inputs
183+ // If ANY input has uppercase letter, match case-sensitively with --smart-case
184+ const hasUpperCase = inputs . some ( input => / [ A - Z ] / . test ( String ( input ) ) ) ;
185+ const ignoreCase = flags . caseSensitive ? false : ( flags . smartCase ? ! hasUpperCase : true ) ;
186+
187+ await fkill ( inputs , {
178188 force : true ,
179- ignoreCase : true ,
189+ ignoreCase,
180190 } ) ;
181191 }
182192} ;
@@ -250,7 +260,7 @@ const listProcesses = async (processes, flags) => {
250260 message : 'Running processes:' ,
251261 pageSize : 10 ,
252262 async source ( term = '' ) {
253- const matchingProcesses = filterAndSortProcesses ( processes , term , searcher ) ;
263+ const matchingProcesses = filterAndSortProcesses ( processes , term , searcher , flags ) ;
254264 return matchingProcesses . map ( process_ => renderProcessForDisplay ( process_ , flags , memoryThreshold , cpuThreshold ) ) ;
255265 } ,
256266 } ) ;
0 commit comments