mathiasbynens / dotfiles

:wrench: .files, including ~/.macos — sensible hacker defaults for macOS

Home Page:https://mths.be/dotfiles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Jarmos-san opened this issue · comments

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 (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:

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 😄