DEV Community

Michael Kochell
Michael Kochell

Posted on • Edited on

Quick Google search from terminal

Note: this only applies to MacOS

Often times while I'm working on a project, I'll need to search for something on the internet to solve a problem. I usually use the search engine created by Google, called Google. When I need to search for something, I always have to stop what I'm doing, and switch over to a browser to type in my search. This may not seem like a big deal because it doesn't take that much time, but in reality this is a context switch. There is a momentary discontinuity in the intentions of your search.

I'd like to remove this obstacle and be able to search without leaving my development environment. This can be accomplished by using the open command on MacOS, and the chromium-browser command on Linux.

Place this script in your PATH with the name "gsearch":

~/scripts/gsearch


#!/bin/sh

# If using mac
open "https://google.com/search?q=$*"

# If using linux and chromium
chromium-browser "https://google.com/search?q=$*"


# Now you can enter a search query like this:
gsearch please help google
Enter fullscreen mode Exit fullscreen mode

hey

A browser tab will then come into focus, showing the results for a Google search of "please help google". Now that's good DX.

Top comments (5)

Collapse
 
rupankarghosh profile image
RupankarGhosh • Edited

First of all there is no open command in Linux,it's a Darwin specific command to open anything using its respective app. In Linux there is xdg-open which should open a specific file in browser. So your post is Mac specific and you should specify this too. πŸ’ŒπŸ‘¨πŸ»β€πŸ’»

Collapse
 
mickmister profile image
Michael Kochell

Noted! I purposely didn't do any research on compatibility to generate more discussion. Thanks for your insight!

Collapse
 
mickmister profile image
Michael Kochell • Edited

Alt-Tab is a practical solution. However, I can be sensitive to sudden visual changes, especially when I'm thinking hard about something. Also the extra step of having to open another tab adds another obstacle for me, even though it is a simple Cmd-T. Anyway, I kind of made this as a joke for my first post. I thought it was a cool trick :)

Collapse
 
arivanamin profile image
Arivan Amin

Any Linux distro with KDE Desktop environment has Krunner which can do that and much more than that you should try it it's amazing

Collapse
 
mickmister profile image
Michael Kochell

I certainly will! Thank you!