diff options
Diffstat (limited to 'modules/core/module-fs.js')
| -rw-r--r-- | modules/core/module-fs.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/core/module-fs.js b/modules/core/module-fs.js index 757d1da..0dea0d5 100644 --- a/modules/core/module-fs.js +++ b/modules/core/module-fs.js @@ -305,6 +305,22 @@ class FileSystemModule { else this.terminal.print(grand + ' match(es)' + (multi ? ' in ' + readFiles + ' file(s)' : ''), 'text-muted'); } } else { + // Piped input wins over the cwd sweep. `cat f | grep x` used to grep the working + // directory, so it could match a file that was never piped — measured 2026-10-27: + // `cat /gdir/in.txt | grep zzz` answered "other.txt:1: zzz in a cwd file". + const piped = this.terminal._pipeInput; + if (piped !== null && piped !== undefined) { + let pipedTotal = 0; + String(piped).split('\n').forEach((line, i) => { + if (!hits(line)) return; + pipedTotal++; + if (!opt.count && !opt.files) this.terminal.print((i + 1) + ': ' + line); + }); + if (opt.files) { if (pipedTotal) this.terminal.print('(stdin)'); } + else if (opt.count) this.terminal.print(String(pipedTotal)); + else if (pipedTotal === 0) this.terminal.print('(no matches)', 'info'); + return; + } const dir = this.terminal.fs.getCurrentDir(); if (!dir) return this.terminal.print('grep: cannot search', 'error'); let total = 0; |