Skip to content

Fix grep highlighting, pwd at /, and cd tab completion - #147

Open
mstellaris wants to merge 1 commit into
rootvc:mainfrom
mstellaris:fix-grep-pwd-cd-completion
Open

mstellaris wants to merge 1 commit into
rootvc:mainfrom
mstellaris:fix-grep-pwd-cd-completion

Conversation

@mstellaris

Copy link
Copy Markdown

Three small bugs in the terminal, each with a test.

grep corrupts its own output

grep highlighted matches with colorText(match, "files"), but files isn't a
style, so no colour was ever applied. Only the reset code \x1b[0;38m was added.
It then ran replaceAll once per match over the already-modified text, so a
pattern that occurs in an escape code (0, 3, 8, ;, [) matches inside
the codes it just inserted. Try su root, then grep 3 README.md: the output
fills with nested escape sequences.

Now: one String.replace with a global RegExp over the original text, and a new
match style (bold red, like GNU grep). An invalid pattern (grep ( README.md)
prints grep: invalid pattern instead of throwing into
"Command failed to load required assets". Patterns stay regexes, as in real grep.
(#141 escapes metacharacters but keeps the files style and the per-match
replaceAll loop, so it doesn't fix this.)

pwd prints // at the root

cd / then pwd printed //, because cwd is stored as / and the code
always prefixed another slash. claude showed the same path in its banner.
Both now use a shared _cwdPath() helper.

cd <Tab> never completes anything

The completion filter kept entries !_DIRS[term.cwd].includes(dir). Every entry
_filesHere() returns is in _DIRS[term.cwd], so the list was always empty.
Now it offers directories: the _DIRS keys (bin, home) and the entries of
/home. Plain files like id_rsa are still excluded.

Tests

  • tests/commands.test.js: pwd table; grep highlights each match once,
    treats the pattern as a regex, and reports an invalid pattern.
  • tests/terminal.test.js: cd completion from /, from /home, a unique
    prefix, and no plain files from ~.

11 new tests, 7 of which fail on the previous code. Full suite: 168 passed.

🤖 Generated with Claude Code

- grep: highlight in one global RegExp pass over the original text with a
  real "match" style. The old loop used a style that doesn't exist and
  re-ran replaceAll per match over already-modified text, so a pattern
  found in an escape code (grep 3 README.md) nested codes into garbage.
  An invalid pattern now prints an error instead of throwing.
- pwd (and the claude banner) printed "//" at the root; both now use a
  shared _cwdPath() helper.
- cd <Tab> filtered out every entry of the current directory, so it never
  completed. It now offers directories: the _DIRS keys and /home entries.

Adds 11 tests; 7 fail on the previous code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Dec 6, 2026

Copy link
Copy Markdown

👷 Deploy request for rootvc-cli-website pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 1f3e96b

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant