lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Fix issues with opening links and files using WSL

Open bottino opened this issue 1 year ago • 1 comments

  • PR Description

This PR fixes to issues with the current implementation of the OSConfig for WSL:

File explorer When using the file explorer from WSL, for instance by pressing "o" in the "Files" menu, the explorer always opens on the default landing page. This is caused by the filepath being expressed in WSL format instead of the expected Windows format. For instance:

  • "/home/myuser/path/to/my/file" should be "\wsl$\MyDistroName\home\myuser\path\to\my\file"
  • "/mnt/c/path/to/my/file" should be "C:\path\to\my\file"

There's a utility to do that in WSL, wslpath. We use it in the Open to format the filename before passing it to the Powershell command

Link URLs Opening links containing ampersands inside lazygit (a pull-request creation page in BitBucket Server, for instance) returns the following Powershell error:

The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double quotation marks ("&") to pass it as part of a string.

We fix it by enclosing the URL in single quotes.

Notes on this PR This is my first PR on this repo, please tell me if something is needed. I read the contributing guide. The OS-specific logic doesn't appear to be tested in integration and unit tests, so I didn't add tests.

  • Please check if the PR fulfills these requirements
  • [x] Cheatsheets are up-to-date (run go generate ./...)
  • [x] Code has been formatted (see here)
  • [ ] Tests have been added/updated (see here for the integration test guide)
  • [ ] Text is internationalised (see here)
  • [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • [ ] Docs have been updated if necessary
  • [x] You've read through your own file changes for silly mistakes etc

bottino avatar Aug 23 '24 19:08 bottino

As an alternative, we could default to using xdg-open for all Linux systems, and refer WSL users to wsl-open.

bottino avatar Sep 01 '24 21:09 bottino

@jesseduffield Is something wrong with the checks? They don't seem to run.

bottino avatar Nov 14 '24 13:11 bottino

This PR will fix #3843

bottino avatar Nov 14 '24 13:11 bottino

@jesseduffield Is something wrong with the checks? They don't seem to run.

First time contributors have to have their changes approved manually before the CI runs them.

mark2185 avatar Nov 14 '24 13:11 mark2185

Do I still need to do something to merge this PR?

bottino avatar Nov 19 '24 18:11 bottino

@jesseduffield can we merge this PR? I don't think I have sufficient rights to do it myself. Many thanks!

bottino avatar Dec 04 '24 08:12 bottino

Since Jesse approved these already, I'll just merge. Thanks for the contribution!

stefanhaller avatar Dec 04 '24 08:12 stefanhaller