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 @@ -17,31 +17,27 @@ let hadError = false;
1717for ( const path of paths ) {
1818 try {
1919 const content = await fs . readFile ( path , "utf-8" ) ;
20- if ( options . b ) {
20+ if ( options . n || options . b ) {
2121 const lines = content . split ( "\n" ) ;
22-
2322 if ( lines [ lines . length - 1 ] === "" ) {
2423 lines . pop ( ) ;
2524 }
26- for ( const line of lines ) {
27- if ( line . trim ( ) !== "" ) {
28- process . stdout . write ( ` ${ lineNumber } ${ line } \n` ) ;
25+
26+ if ( options . b ) {
27+ for ( const line of lines ) {
28+ if ( line . trim ( ) !== "" ) {
29+ process . stdout . write ( ` ${ lineNumber } ${ line } \n` ) ;
30+ lineNumber ++ ;
31+ } else {
32+ process . stdout . write ( "\n" ) ;
33+ }
34+ }
35+ } else if ( options . n ) {
36+ for ( const line of lines ) {
37+ process . stdout . write ( `${ String ( lineNumber ) . padStart ( 6 ) } \t ${ line } \n` ) ;
2938 lineNumber ++ ;
30- } else {
31- process . stdout . write ( "\n" ) ;
3239 }
3340 }
34- } else if ( options . n ) {
35- const lines = content . split ( "\n" ) ;
36-
37- if ( lines [ lines . length - 1 ] === "" ) {
38- lines . pop ( ) ;
39- }
40-
41- for ( const line of lines ) {
42- process . stdout . write ( `${ String ( lineNumber ) . padStart ( 6 ) } \t ${ line } \n` ) ;
43- lineNumber ++ ;
44- }
4541 } else {
4642 process . stdout . write ( content ) ;
4743 }
You can’t perform that action at this time.
0 commit comments