DuckDuckGo from terminal

2020-07-28

Here is the end result how you can open the Duckduckgo search in your favorite browser, straight from the terminal:

? What does number 42 mean

I'm using macOS in this post.

Requirement brew install jq

In your bash config, e.g .zshrc add the following

urlencode()
{
  local args="$@"
  jq -nr --arg v "$args" '$v|@uri';
}

duckduckgo()
{
  open "https://duckduckgo.com/?q=$(urlencode "$@")"
}

alias '?'='duckduckgo'

Open in specific browser

If you want to open the result in spesific browser instead of your system default, you can e.g make a small change to open it in Firefox like this:

open -a firefox  "https://duckduckgo.com/?q=$(urlencode "$@")"

Open the Duckduckgo in terminal

If you are hardcore user of the terminal you can instead use the following (this is the original way that was used by the Heiker)

lynx "https://lite.duckduckgo.com/lite/?q=$(urlencode "$@")"

Sources

Idea is based on the Heiker's bash alias on Dev.to comments

  • duckduckgo
  • terminal