8000 grep includes the i flag (#876) · shelljs/shelljs@4113a72 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4113a72

Browse files
ppsleepnfischer
authored andcommitted
grep includes the i flag (#876)
grep includes the i flag to ignored upper/lower case differences
1 parent 8dae55f commit 4113a72

File tree

6 files changed

+18
-2
lines changed

6 files changed

+18
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ include the base directories (e.g., `lib/resources/file1` instead of just `file1
362362
Available options:
363363

364364
+ `-v`: Invert `regex_filter` (only print non-matching lines).
365-
+ `-l`: Print only filenames of matching files
365+
+ `-l`: Print only filenames of matching files.
366+
+ `-i`: Ignore case.
366367

367368
Examples:
368369

src/grep.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ common.register('grep', _grep, {
77
cmdOptions: {
88
'v': 'inverse',
99
'l': 'nameOnly',
10+
'i': 'ignoreCase',
1011
},
1112
});
1213

@@ -17,7 +18,8 @@ common.register('grep', _grep, {
1718
//@ Available options:
1819
//@
1920
//@ + `-v`: Invert `regex_filter` (only print non-matching lines).
20-
//@ + `-l`: Print only filenames of matching files
21+
//@ + `-l`: Print only filenames of matching files.
22+
//@ + `-i`: Ignore case.
2123
//@
2224
//@ Examples:
2325
//@
@@ -41,6 +43,9 @@ function _grep(options, regex, files) {
4143
}
4244

4345
var grep = [];
46+
if (options.ignoreCase) {
47+
regex = new RegExp(regex, 'i');
48+
}
4449
files.forEach(function (file) {
4550
if (!fs.existsSync(file) && file !== '-') {
4651
common.error('no such file or directory: ' + file, 2, { continue: true });

test/grep.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ test('-l option', t => {
137137
t.is(result.split('\n').length - 1, 2);
138138
});
139139

140+
test('-i option', t => {
141+
const result = shell.grep('-i', 'test', 'test/resources/grep/case1', 'test/resources/grep/case1.txt',
142+
'test/resources/grep/case1.js');
143+
t.falsy(shell.error());
144+
t.is(result.split('\n').length - 1, 3);
145+
});
146+
140147
test('the pattern looks like an option', t => {
141148
const result = shell.grep('--', '-v', 'test/resources/grep/file2');
142149
t.falsy(shell.error());

test/resources/grep/case1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+< 6890 div class="diff-text-inner">Test3

test/resources/grep/case1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test3

test/resources/grep/case1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TEST3

0 commit comments

Comments
 (0)
0