DuckDuckGo From Your Terminal

It’s been quite some time since I became frustrated with Google’s shady business practices and insatiable appetite for consumers’ personal information. After stumbling upon DuckDuckGo I made the switch and haven’t looked back.

Since I conduct dozens of searches per day, anything that will make getting to the relevant search results faster is invaluable. Modern web browsers let you access search results after entering your query in the address field. However this approach requires you to have already activated your browser of choice and created a new window/tab to avoid clobbering your existing context.

LaunchBar ships with a DuckDuckGo search template, making it easy to jump straight to your desired search results with just a few keystrokes whatever you happen to be doing your Mac.

But, as a developer who spends excessive amounts of time in terminal windows, I figured it was possible to make it even easier to get to search results in my preferred web browser from the command line… and thus ddg was born. Behold, the world’s simplest (yet indispensable) shell script:

#!/bin/sh

open "https://duckduckgo.com?q=$@"

Because ddg simply forwards the script’s arguments on as your search query, Duck Duck Go’s excellent Bangs feature is free, ex:

# Feelin' lucky
ddg '! launchbar'

# Mozilla Developer Center
ddg '!mdc css-grid'

# Apple Developer Center
ddg '!adc WebURLsWithTitlesPboardType'

# YouTube
ddg '!yt ronan rack'

(Note the single quotes wrapping the search terms above; using double quotes will require you to escape the ! to prevent its shell interpolation.)

Should no arguments be provided, you can always initiate your search from your browser once it is activated by the script.