Mac users have this magic convenience of typing open index.html
into their terminal to open a file from their current directory in the browser. Those of us on WSL aren't so lucky. If you're lucky, the open
command will open a windows directory. Cool, I guess? But not exactly super helpful. The internet abounds with recommendations --- from trying xdg-open
, configuring your www-browser
defaults, and setting your PATH
environments to some even more convoluted methods. But the question remains: what's the easiest way to open an HTML file in the browser from WSL?
The closest thing I've found is to use the Windows Subsystem for Linux's explorer.exe
command. Assuming you've set your browser environment variable in bash, then typing something lile explorer.exe index.html
should open the file index.html
in your default browser. If that works, congrags! That's the simplest version of Mac's open
command. Well, sort of...
Typing explorer.exe
is still a little bit of a handful, and I'm lazy. I mean open
is four characters, and explorer.exe
is twelve. That's three times as many characters. No thanks!
By default, there are two problems when you try to open html files on a Mac:1. When you double click it opens in Safari = annoying!2. Even if you right clic. HTM files are most commonly known as HTML files, which are the files that contain HTML language. If you open an HTM file in a text editor like Notepad or TextEdit, you’ll only see lines of text and symbols. But when you open HTM files in a web browser like Safari, Edge, or Chrome, you'll see the web page created by the code. Favorite browser, choose “Open File.” (or “Open.” using Windows XP and Internet Explorer) from the File menu and navigate to your “index.html” file. Select it and click “Open”. Mac our t by clicking on the file icon and then on on. Then click “Browse” to get a browse dialog and navigate to where you saved your file. To open the filename.html in the default browser use: open filename.html open is a very good command as well as a feature of Mac OS that makes me fall in love with it more deeper. It automatically chooses the appropriate default app to open the file. And in case you want to open a file in your desired app rather then default.
Wouldn't it be nice if we could do something simpler? How about see index.html
? Fortunately, we can leverage the ability to create aliases in bash to make this dream a reality. Just drop the following three lines directly into your terminal:
You're done! No need to play around in your config files. 🙌 Next time you need to open that index.html
file, all you need to do is type see index.html
and watch the magic happen. And it's one fewer character than those Mac folks. Just imagine what you could do with that kind of time savings...
May 4, 2013 11:51 PM
Great guide, thanks John.
Just a note, in case anyone has the same issue. At first I couldn't get this to work. I tried logging out and back in (still no joy), then restarting the mac (still no joy).
Try doing both of those first. However, if, like me, you still can't get the local host site to load, try the following: You should find a file at /Library/WebServer/Documents/index.html.en . This contains the text 'It works!' referred to in the post. What I did was duplicate that file in the same folder and changed the duplicate's name to 'index.html', leaving the original in situ.
How To Open Html Files
Both local and user sites then loaded. After which, I was able to delete the duplicated file and everything now works without issue. Just to be clear, leave the original file index.html.en where it is, untouched and unharmed throughout this step.
Open Html File On Macbook
Not sure why I had to take this mysterious detour - probably something local to my machine, but if you're having trouble after following the guide above, see if it helps.
How To Open Html File On Mac
May 4, 2013 11:51 PM