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 '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!

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: