DuckDuckGo in a Shell

The tip

When I go outside my terminal, I am kind of lost. I control everything from my terminal and I hate clicking. That’s why I found a small tip today to open a search on DuckDuckGo directly from the terminal. It redirects me to my default browser in the background, which is the expected behavior.

First, I create a function called duckduckgo:

function duckduckgo {
    query=`php -r 'echo urlencode($argv[1]);' "$1"`
    open ''$query

Note how I (avoid to) deal with quotes in $1.

Then, I just have to create an alias called ?:

alias '?'='duckduckgo'

And here we (duckduck) go!

$ ? "foo bar's baz"

You can see the commit that adds this to my “shell home framework”.

Oh, and to open the default browser, I use open (1), like this:

alias open='open -g'

Hope it helps!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s