File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
implement-shell-tools/cat Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -23,18 +23,21 @@ if (files.length === 0) {
2323 process . exit ( 1 ) ;
2424}
2525
26+ // Global counters across all files
27+ let lineCounter = 1 ;
28+ let nonBlankCounter = 1 ;
29+
2630for ( const file of files ) {
2731 try {
2832 let content = await fs . readFile ( file , 'utf-8' ) ;
2933 const lines = content . split ( '\n' ) ;
3034
3135 if ( showNoBlankNumb ) { // Number only non-blank lines
32- let counter = 1 ;
3336 content = lines . map ( line =>
34- line . trim ( ) === '' ? '' : `${ counter ++ } \t${ line } `
37+ line . trim ( ) === '' ? '' : `${ nonBlankCounter ++ } \t${ line } `
3538 ) . join ( '\n' ) ;
3639 } else if ( showLineNumb ) { // Number all lines
37- content = lines . map ( ( line , i ) => `${ i + 1 } \t${ line } ` ) . join ( '\n' ) ;
40+ content = lines . map ( ( line ) => `${ lineCounter ++ } \t${ line } ` ) . join ( '\n' ) ;
3841 }
3942 console . log ( content ) ;
4043 } catch ( err ) {
You can’t perform that action at this time.
0 commit comments