mathiasbynens / dotfiles

:wrench: .files, including ~/.macos — sensible hacker defaults for macOS
https://mths.be/dotfiles
MIT License
30.01k stars 8.74k forks source link

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

Open Jarmos-san opened 2 years ago

Jarmos-san commented 2 years ago

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 😄