Repository navigation
Description
Describe the bug
The Preview in Browser option for a new pull request (via gh pr create) fails with the following error when used in WSL (I'm using the Pengwin distro on WSL2):
exec: "xdg-open": executable file not found in $PATH
As a result, you lose the PR body you've typed into the editor and have to start the PR creation process again.
$ gh --version
gh version 0.7.0 (2020-04-22)
https://github.com/cli/cli/releases/tag/v0.7.0
$ wslsys
Locale: en_AU
Release Install Date: Sat Apr 18 18:02:48 AEST 2020
Branch: rs_prerelease
Build: 19608
Full Build: 19608.1000.amd64fre.rs_prerelease.200410-1438
Display Scaling: 1
Windows Theme: light
Windows Uptime: 0d 13h 55m
WSL Uptime: 0d 5h 16m
WSL Release: Pengwin
WSL Kernel: Linux 4.19.104-microsoft-standard
Packages Count: 659
Steps to reproduce the behavior
- Using WSL on Windows 10
- Follow the prompts in
gh pr create - Select the
Preview in Browseroption
Expected vs actual behavior
This error is thrown and the command exits, losing all information:
exec: "xdg-open": executable file not found in $PATH
Ideally it should open the browser on the host to preview the PR, as if it was run on the host directly. wslview is included with most WSL distros and can be used to open the browser in Windows 10. More information: https://github.com/wslutilities/wslu
The alternative would be to provide the user the option to submit the PR directly or display a URL to manually paste into the browser for the preview.
Logs
valorin@Pengwin:~/dev/project/www (FB834)$ gh pr create
Creating pull request for FB834 into master in project/project-www
? Title FB834: Tweak width of invoice to/from/status for comfort
? Body <Received>
? What's next? Preview in browser
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 4 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.43 KiB | 1.43 MiB/s, done.
Total 7 (delta 6), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (6/6), completed with 6 local objects.
remote:
remote: Create a pull request for 'FB834' on GitHub by visiting:
remote: https://github.com/project/project-www/pull/new/FB834
remote:
To github.com:project/project-www.git
* [new branch] HEAD -> FB834
Branch 'FB834' set up to track remote branch 'FB834' from 'origin'.
Opening github.com/project/project-www/compare/master...FB834 in your browser.
exec: "xdg-open": executable file not found in $PATH
Activity
mislav commentedon May 7, 2020
Ouch, sorry for that. We should try to save your PR title & body on failure so you can reuse those on next retry.
Thanks for sharing that! We will try to detect and use that in the future. Until then, you can set
export BROWSER=wslviewin the shell where you useghand GitHub CLI will use that executable when opening a browser.valorin commentedon May 7, 2020
Awesome, thanks! I'll enable
export BROWSER=wslviewnow. 😁viperfx commentedon May 9, 2020
For me, it opens at
http://127.0.0.1:39337/callback?browser_session_id=....and chrome cannot connect to this server.EDIT:
Followed comment in #597 and its working now!
jetersen commentedon Jun 12, 2020
This is my tiny hack for
xdg-opennot being available and without need to installxdg-utilsother tools might stumble ie.kubeloginuse these two tweaks for the best experience on WSL.
mislav commentedon Jun 12, 2020
@jetersen Thanks, but this seems like more steps than just setting
export BROWSER=wslviewin your shell config file 🤔 Do you recommend people to take yours over the environment variable approach?jetersen commentedon Jun 12, 2020
No I suggest both fixes to have the most success with compatibility.
I still use
export BROWSER=wslviewfor those programs that support it.Sadly
kubeloginusespkg/browserwhich seems unmaintained: https://github.com/pkg/browser/pulse/monthlyPRs are there that would fix compatiblity.
I put my
BROWSER=wslviewinto the/etc/environmentwhen multiple users are involved on WSL.mislav commentedon Jun 17, 2020
@jetersen Ah I see now that you were not solving this issue just for
gh, but for other tools as well. Thanks!felipecrs commentedon Jun 19, 2020
I take a similar approach as @jetersen, but easier:
sudo ln -s $(which wslview) /usr/local/bin/xdg-openJust run and you should be good to go.
jetersen commentedon Jun 19, 2020
@felipecassiors good point, I did not think of symlinking.
I suspect search engines are leading a lot of users to this issue.
Stilborg commentedon Feb 8, 2021
Thx @jetersen you saved me! , fandme verdensklasse