File tree Expand file tree Collapse file tree
implement-shell-tools/cat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/env node
2+
3+
4+
25import { program } from "commander" ;
36import { promises as fs } from "node:fs" ;
47import process from "node:process" ;
@@ -22,15 +25,18 @@ for (const filePath of argv) {
2225
2326 if ( lines [ lines . length - 1 ] === "" ) lines . pop ( ) ;
2427
25- lines . forEach ( ( line , index ) => {
28+ let count = 0 ;
29+
30+ lines . forEach ( ( line ) => {
2631 if ( options . nonBlank ) {
27- if ( line . trim ( ) !== "" ) {
32+ if ( line !== "" ) {
33+ count ++ ;
2834 process . stdout . write (
29- `${ ( index + 1 ) . toString ( ) . padStart ( 6 ) } ${ line } \n` ,
35+ `${ count . toString ( ) . padStart ( 6 ) } ${ line } \n` ,
3036 ) ;
3137 } else process . stdout . write ( `${ line } \n` ) ;
3238 } else if ( options . number ) {
33- process . stdout . write ( `${ ( index + 1 ) . toString ( ) . padStart ( 6 ) } ${ line } \n ` ) ;
39+ process . stdout . write ( `${ ( count ++ + 1 ) . toString ( ) . padStart ( 6 ) } ${ line } \t ` ) ;
3440 } else {
3541 process . stdout . write ( `${ line } \n` ) ;
3642 }
You can’t perform that action at this time.
0 commit comments