What a Bash command is really doing, as far as retrieval is concerned.
(cmd)
| 771 | |
| 772 | /** What a Bash command is really doing, as far as retrieval is concerned. */ |
| 773 | function bashIntent(cmd) { |
| 774 | const c = String(cmd || ''); |
| 775 | // A heredoc or a redirect is WRITING a file — `cat <<EOF > x` must not read |
| 776 | // as a Read. |
| 777 | if (!/<</.test(c) && !/>\s*\S/.test(c)) { |
| 778 | const m = BASH_READ_RE.exec(c); |
| 779 | if (m) { |
| 780 | // Drop flags and numeric arguments (`sed -n '100,200p' lib/x.js`), then |
| 781 | // take the last path-shaped token. |
| 782 | const args = m[1].split(/\s+/).filter((a) => a && !a.startsWith('-') && !/^['"]?\d/.test(a)); |
| 783 | const path = args.reverse().find((a) => /[/.]/.test(a)); |
| 784 | if (path) return { kind: 'read', path: path.replace(/^['"]|['"]$/g, '') }; |
| 785 | } |
| 786 | } |
| 787 | if (BASH_SEARCH_RE.test(c)) return { kind: 'search' }; |
| 788 | return null; |
| 789 | } |
| 790 | |
| 791 | const normPath = (p) => String(p ?? '').replace(/\\/g, '/').replace(/^\.\//, ''); |
| 792 | /** Same file, with either side repo-relative and the other absolute. */ |
no test coverage detected