DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Make iTerm Open Links in Chrome Instead of Safari
Jackson Reeves
Jackson Reeves

Posted on

Make iTerm Open Links in Chrome Instead of Safari

Do you prefer to do all your development work in Chrome but still want to have Safari as your default browser? Sick of having iTerm automatically open all links in Safari instead of Chrome, and then having to copy said link and paste it into Chrome yourself? That takes up so many valuable seconds!

Inspite of all my best research, I wasnโ€™t able to find a way to configure this in iTermโ€™s preferences. Sure, thereโ€™s the Context Menu Items for Smart Selection Rule thatโ€™s mentioned in this Stack Overflow answer, but I wasnโ€™t able to get that to do anything. Like, at all. But maybe Iโ€™m just stupid.

Lacking an official approach, I did stumble across this hack: Add BROWSER=chrome to your .env file. Going forward, whenever you npm start, it should open with Chrome (even if Safari, or whatever other app, is your default browser).

A few caveats:

  1. You have to do this individually with every repo going forward. But, on the plus side, once you do it initially with that repo, you should never need to worry about it opening in Chrome.
  2. React apps come with a lot of Node modules pre-installed. ENV is not one of them. Youโ€™ll need to npm i dotenv after you npx create-react-app. Then, of course, touch .env once youโ€™re in the repoโ€™s main folder, so the file will be created at the top level. Interestingly, after merely creating the file and storing the above string in it, you donโ€™t need to do anything else. As in, you donโ€™t need to require('dotenv').config() in your index.js file or anywhere else (which I had to do with my other Node projects). If these additional steps sound unappealing, you could also just run this one, slightly longer line every time you plan to do an npm start: just type BROWSER=chrome npm start, which achieves the same effect as the above configuration.
  3. This approach wouldnโ€™t work with any non-Node projects (React is Node compliant). So this wouldnโ€™t work for any of vanilla JavaScript repos. Or anything in any other programming language. However, there may be some .env analog in those situations. Plus, if youโ€™re opening a file from the terminal, you can always type open -a chrome index.html instead of open index.html (or whatever file) in order to make it open in Chrome. Not as simple, but it works.
  4. Every OS handles this a little differently. Windows uses chrome, Linux uses google-chrome, and Mac uses google chrome. So depending on your computer, you may need to type something different after BROWSER= in your .env file. (I have a Mac, but chrome works for me; however, I think thatโ€™s because I renamed the Chrome app in my Applications folder from Google Chrome to just Chrome forever ago. TLDR: Try them out until you get a fit, check what your Chrome app is specifically named in your Applications folder if none of those are working, and try wrapping it in quotes if you need to use the two words google chrome.)

h/t to the Stack Overflow answer that finally led me to this approach

Top comments (0)

๐ŸŒš Browsing with dark mode makes you a better developer.

It's a scientific fact.