Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tilde path handling in terminal links #5813

Closed
wants to merge 1 commit into from
Closed

Conversation

Pym
Copy link

@Pym Pym commented Feb 16, 2025

This PR improves the handling of tilde (~) in clickable paths within the terminal, making it more consistent with standard terminal behavior.

Related to issue #1972 and PR #5801

Changes

Core Functionality

  • Enhance path handling in Surface.zig to properly expand tilde paths
  • Update URL regex pattern in config/url.zig to recognize standalone tilde
  • Clean up path processing in renderer/link.zig for better maintainability

Test Coverage

Added comprehensive test cases in url.zig to verify:

  • Standalone tilde (~) detection and expansion
  • Tilde with path (~/path) handling
  • Tilde in text context (cd ~ to go home)

Impact

These changes ensure:

  1. Clicking on a standalone ~ opens the home directory
  2. Paths starting with ~/ correctly expand to the full home directory path
  3. Existing path patterns and URL detection remain unaffected

  - Improve path handling in Surface.zig to correctly expand standalone tilde (~) to $HOME
  - Update URL regex in config/url.zig

This change ensures that:
  - Standalone tilde (~) is clickable and opens the home directory
  - Paths starting with ~/ correctly expand to the home directory
  - Other path patterns remain unchanged

Add test cases for tilde path handling in url.zig
@Pym Pym requested review from a team as code owners February 16, 2025 23:52
@Pym Pym changed the title Fix Tilde Path Handling in Terminal Links Fix tilde path handling in terminal links Feb 16, 2025
Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of repeated logic we should stop doing since it is very platform-specific. i.e. the HOME env var is not correct to use even on macOS (if its not set) nor Windows when we get there. Additionally, std.posix won't be available on Windows so that's no good either.

I'm also curious how this interacts with OSC8 hyperlinks and how other terminals handle this scenario. Can any terminal program sending tilde-paths via OSC8 and have it open? (I can't even recall if you can set file URLs with OSC8 to be honest it's been awhile since I looked at that spec).


// Handle paths starting with ~
if (str.len > 0 and str[0] == '~') {
const home = std.posix.getenv("HOME") orelse "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using internal_os.expandHome instead of repeating this logic everywhere.

@mitchellh mitchellh added the feedback-requested Discussion needs feedback before anything can be done. label Feb 17, 2025
@Pym
Copy link
Author

Pym commented Feb 17, 2025

Thanks @mitchellh for this detailed feedback.

Indeed, I am new to Zig and I went a bit too fast in my implementation, without taking into account the cross-platform aspects and the reuse of existing code.

I will take the time to study the OSC8 specification in more detail. I will come back with an improved version of this PR!

@mitchellh
Copy link
Contributor

Appreciate it. Please reopen this PR when you do so or open a new one, I'd rather not a have a stale PR dangling. Thank you!

@mitchellh mitchellh closed this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback-requested Discussion needs feedback before anything can be done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants