Menu

mnt.io

DuckDuckGo in a Shell

Written the .

I just would like to share a small tip to use the awesome (meta) search engine, namely DuckDuckGo, in a Shell.

DuckDuckGo's logo

DuckDuckGo's logo.

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 'https://duckduckgo.com/?q='$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!