fix: support absolute paths in Output and Screenshot commands#742
Open
tmchow wants to merge 1 commit intocharmbracelet:mainfrom
Open
fix: support absolute paths in Output and Screenshot commands#742tmchow wants to merge 1 commit intocharmbracelet:mainfrom
tmchow wants to merge 1 commit intocharmbracelet:mainfrom
Conversation
The lexer treats `/` as a regex delimiter, so `Output /tmp/demo.gif`
tokenizes as REGEX("tmp") + STRING("demo.gif") and the parser rejects
it. This also breaks the `vhs new` template which generates absolute
Output paths.
Add a shared parsePathArgument helper that reconstructs absolute paths
from the REGEX + STRING token sequence when the parser expects a file
path. Relative paths still use the existing STRING token path.
Fixes charmbracelet#741
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Output /tmp/demo.giffails with parser errors because the lexer treats/as a regex delimiter. The path/tmp/demo.giftokenizes asREGEX("tmp")+STRING("demo.gif")instead of a single path token, andparseOutput()rejects the unexpected REGEX.This also breaks the template that
vhs newgenerates, which uses an absolute Output path.Fixes #741
Root Cause
In
lexer/lexer.go,case '/'always creates a REGEX token viareadRegex('/'). The parser expects STRING after Output but sees REGEX, producing: "Expected file path after output."The fix is in the parser, not the lexer. The
/character is genuinely ambiguous (regex vs path), but the parser knows the context: afterOutput/Screenshot, a path is expected. AfterWait, a regex is expected.Changes
Added
parsePathArgument()inparser/parser.gothat accepts both STRING tokens (relative paths, existing behavior) and REGEX + STRING sequences (absolute paths like/tmp/demo.gif). BothparseOutput()andparseScreenshot()use this shared helper.Testing
Added
TestParseAbsolutePathscovering:Output /tmp/demo.gif(absolute GIF)Output /tmp/demo.mp4(absolute MP4)Output /home/user/recordings/demo.webm(deep absolute path)Output /frames/(absolute directory output)Output examples/out.gif(relative path, unchanged)Output frames/(relative directory, unchanged)Screenshot /tmp/screenshot.png(absolute screenshot)Screenshot examples/screenshot.png(relative screenshot, unchanged)All 51 existing tests pass.
go vetandgofumptclean.Before
After
Note: This contribution was developed with AI assist w/ Codex.