fix: handle root cwd when launched from GUI without terminal#4
Draft
thdxr wants to merge 1 commit intopithings:mainfrom
Draft
fix: handle root cwd when launched from GUI without terminal#4thdxr wants to merge 1 commit intopithings:mainfrom
thdxr wants to merge 1 commit intopithings:mainfrom
Conversation
When apps are launched from macOS Finder, Windows Explorer, or other
GUI environments without a terminal, process.cwd() returns the root
directory ('/' on Unix, 'C:\' on Windows). This caused issues because:
1. The default preopens mapped '.' to root, which is rarely the intended
search directory in GUI apps
2. Reading from root in sandboxed environments can fail or cause
permission issues
The fix adds isRootPath() helper using path.parse() to detect root
directories on both Unix ('/') and Windows ('C:\', 'D:\', etc.).
When cwd is root, getDefaultPreopens() returns {} instead of mapping
'.' to root. This forces users to provide explicit absolute paths
when running in these environments.
Changes:
- lib/index.mjs: Add isRootPath() and getDefaultPreopens() helpers
- test/ripgrep.test.mjs: Add regression test for root cwd scenario
- README.md: Document the behavior and workaround for GUI environments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When apps are launched from macOS Finder, Windows Explorer, or other GUI environments without a terminal,
process.cwd()returns the root directory:/C:\,D:\, etc.The default
preopens: { ".": process.cwd() }then maps.to root, which:Solution
isRootPath()helper usingpath.parse()to detect root directories on both Unix and WindowsgetDefaultPreopens()returns{}instead of mapping.to rootChanges
lib/index.mjs: +24 lines (isRootPath+getDefaultPreopenshelpers)test/ripgrep.test.mjs: +24 lines (regression test for root cwd scenario)README.md: Updated documentation with GUI environment noteTesting
All 28 tests pass, including the new regression test that simulates the root cwd scenario.
Checklist