mathiasbynens / mathiasbynens/dotfiles

Normalised `open` doesn't work as expected on WSL2

Open
#964 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Shell
Stars
31.5k
Forks
8.4k
PR merge metrics
No merged PRs in 30d

Description

First of thanks for sharing your dotfiles, it's been a major source of inspiration to setup my WSL2 machine lately.

So, I tried using the normalised [`open`](https://github.com/mathiasbynens/dotfiles/blob/66ba9b3cc0ca1b29f04b8e39f84e5b034fdb24b6/.functions#L144) _(line #144 of the `.functions` file_) code snippet on a WSL2 Ubuntu distro & it won't work as expected. I suspect `grep` can't read the `/proc/version` file due to missing `sudo` privileges(?). I bet a better solution would be to `grep` the output of `uname -r` which doesn't require `sudo` privileges.

**A possible "_better_" solution could be**:

```bash
if [ ! $(uname -s) = 'Darwin' ]; then
if [ $(uname -r | grep -i 'microsoft') ]; then
# Ubuntu on Windows using the Linux subsystem
alias open='explorer.exe';
else
alias open='xdg-open';
fi
fi
```

EDIT: Provided a "_better_" solution & I don't mind opening a PR with the above changes 😄

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the normalized `open` snippet at `.functions` line 144 and compare its `/proc/version` detection with the proposed `uname -r` check. Test the behavior on a WSL2 Ubuntu distro, including the `explorer.exe` and `xdg-open` paths; done means `open` selects the expected command without requiring elevated privileges.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, shell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.