
Show HN: Ddgr – search DuckDuckGo from your terminal - apjana
https://github.com/jarun/ddgr
======
apjana
ddgr is a cmdline utility to search DuckDuckGo from the terminal. While
googler is extremely popular among cmdline users, in many forums the need of a
similar utility for privacy-aware DuckDuckGo came up. DuckDuckGo Bangs are
super-cool too! So here's ddgr for you!

Unlike the web interface, you can specify the number of search results you
would like to see per page; more convenient than skimming through 30-odd
search results per page. The default interface is carefully designed to use
minimum space without sacrificing readability.

A big advantage of ddgr over googler is DuckDuckGo works over the Tor network.

ddgr is available in the repos of many distros as well as on PyPI.

~~~
I_complete_me
Great. Well done on this. I now have a new favourite dictionary on my zsh CLI
thus: alias -g define='BROWSER=w3m ddgr \\!wordnik ' Thank you!

~~~
apjana
Thanks for sharing this.

------
msla
Reminds me of surfraw:

[https://gitlab.com/surfraw/Surfraw](https://gitlab.com/surfraw/Surfraw)

[https://wiki.archlinux.org/index.php/Surfraw](https://wiki.archlinux.org/index.php/Surfraw)

[https://en.wikipedia.org/wiki/Surfraw](https://en.wikipedia.org/wiki/Surfraw)

> Surfraw (Shell Users Revolutionary Front Rage Against the Web) is a free
> public domain POSIX-compliant (i.e. meant for Linux, FreeBSD etc.) command-
> line shell program for interfacing with a number of web-based search
> engines.[1] It was created in July 2000 by Julian Assange[2] and is licensed
> in the public domain[3] and written in the Bourne shell language.

Yes, it's apparently _that_ Julian Assange.

~~~
apjana
The number of dependencies is very high. From Ubuntu 18.04:

    
    
      $ sudo apt install surfraw
      Reading package lists... Done
      Building dependency tree         
      Reading state information... Done
      The following additional packages will be installed:
        libalgorithm-c3-perl libb-hooks-endofscope-perl libcache-perl libclass-accessor-chained-perl
        libclass-c3-perl libclass-c3-xs-perl libclass-data-inheritable-perl libclass-errorhandler-perl
        libclass-inspector-perl libclass-singleton-perl libdata-optlist-perl libdata-page-perl
        libdatetime-format-mail-perl libdatetime-format-w3cdtf-perl libdatetime-locale-perl libdatetime-perl
        libdatetime-timezone-perl libdevel-caller-perl libdevel-lexalias-perl libdevel-stacktrace-perl
        libeval-closure-perl libexception-class-perl libfeed-find-perl libfile-nfslock-perl
        libfile-sharedir-perl libheap-perl liblwp-authen-wsse-perl libmodule-implementation-perl
        libmodule-pluggable-perl libmro-compat-perl libnamespace-autoclean-perl libnamespace-clean-perl
        libpackage-stash-perl libpackage-stash-xs-perl libpadwalker-perl libparams-util-perl
        libparams-validate-perl libparams-validationcompiler-perl libreadonly-perl libref-util-perl
        libref-util-xs-perl libspecio-perl libsub-exporter-perl libsub-identify-perl libsub-install-perl
        liburi-fetch-perl liburi-template-perl libvariable-magic-perl libwww-opensearch-perl libxml-atom-perl
        libxml-feed-perl libxml-libxslt-perl libxml-rss-perl libxml-xpath-perl surfraw-extra
      Suggested packages:
        libtest-fatal-perl screen
      The following NEW packages will be installed:
        libalgorithm-c3-perl libb-hooks-endofscope-perl libcache-perl libclass-accessor-chained-perl
        libclass-c3-perl libclass-c3-xs-perl libclass-data-inheritable-perl libclass-errorhandler-perl
        libclass-inspector-perl libclass-singleton-perl libdata-optlist-perl libdata-page-perl
        libdatetime-format-mail-perl libdatetime-format-w3cdtf-perl libdatetime-locale-perl libdatetime-perl
        libdatetime-timezone-perl libdevel-caller-perl libdevel-lexalias-perl libdevel-stacktrace-perl
        libeval-closure-perl libexception-class-perl libfeed-find-perl libfile-nfslock-perl
        libfile-sharedir-perl libheap-perl liblwp-authen-wsse-perl libmodule-implementation-perl
        libmodule-pluggable-perl libmro-compat-perl libnamespace-autoclean-perl libnamespace-clean-perl
        libpackage-stash-perl libpackage-stash-xs-perl libpadwalker-perl libparams-util-perl
        libparams-validate-perl libparams-validationcompiler-perl libreadonly-perl libref-util-perl
        libref-util-xs-perl libspecio-perl libsub-exporter-perl libsub-identify-perl libsub-install-perl
        liburi-fetch-perl liburi-template-perl libvariable-magic-perl libwww-opensearch-perl libxml-atom-perl
        libxml-feed-perl libxml-libxslt-perl libxml-rss-perl libxml-xpath-perl surfraw surfraw-extra
      0 upgraded, 56 newly installed, 0 to remove and 0 not upgraded.
      Need to get 3,883 kB of archives.
      After this operation, 29.0 MB of additional disk space will be used.
      Do you want to continue? [Y/n] n
      Abort.

~~~
darkpuma
Seems like your average Node package. CPAN was ahead of it's time.

------
theophrastus
Are the bang searches supposed to _always_ open a gui browser? Because they
seem that way. Search Hacker News for "ddgr" and it opens up (in my case) a
tab on firefox:

    
    
         ddgr \!hn ddgr

~~~
TheGrassyKnoll
With bangs, I'm getting a new tab in Firefox as well.

~~~
apjana
What's the output of `echo $BROWSER`?

~~~
theophrastus
In my case BROWSER isn't set. And yet ddgr still found my firefox in another
workspace and opened a tab on it. I was just wondering if there's a means to
force a terminal/text output from something akin to:

    
    
       ddgr \!ety glaucous

~~~
apjana
This is inherited from Python's webbrowser module. It would find a GUI browser
by default. Please set `BROWSER` to your preferred text-based browser. To
force use the GUI browser, use the prompt key `O` or the progrma option
`--gb`.

As you can see, you can only have it one way (either text or GUI by default)
and we kept it the default one.

~~~
dontbenebby
Hi, maybe there's something wrong with my environment, but I installed Lynx
via brew, got the location (which brew|pbcopy) then exported the location to
an environment variable (export BROWSER=/usr/local/bin/lynx).

But when I select something in ddgr, it says it's opened lynx but the display
still just shows a list of 10 results.

If I hit q, it drops me back to ddgr, and then a quit again exits the program.

I don't want to jump to saying the issue is ddgr but was a little surprised.

It's still very useful since a lot of what I do needs images anyways, and it's
IMHO silly to try to do GUI browsing in terminal, just thought I'd mention it.

Thanks for being so active in the comments!

(Trying to be extra positive since I know HN can be a little hypercritical,
and the people who loved it aren't necessarily going to drop in and say so
beyond an upvote :) )

~~~
apjana
Works fine for me. Steps right out of the terminal:

    
    
      1. sudo apt install lynx
      2. export BROWSER=lynx
      3. ddgr hello world
      4. Press 1 (to open the first result in lynx)
    

The site is opened in lynx as expected.

~~~
dontbenebby
Thanks, that was my issue (I was typing the literal path to lynx not just
"lynx")

------
vaer-k
Can you search by any duration, like googler can, or does duckduckgo prevent
you from implementing that? That's my biggest complaint about ddg: can't even
search by past year

~~~
jolmg
I see a dropdown on a search results page that says "Any Time". On clicking
it, you get the options "Past Day", "Past Week", "Past Month".

~~~
vaer-k
Yes, but that's it. No "past year" or custom ranges.

------
bootcat
Something related, I made a DuckDuckGo Images API here -
[https://github.com/deepanprabhu/duckduckgo-images-
api](https://github.com/deepanprabhu/duckduckgo-images-api).

This gets image search results and can be embedded into other projects !

------
jaequery
What’s so good about DDG? I’ve used it a few times but i still don’t get the
appeal to it

~~~
cyphar
The no tracking policy, and the large amount of built-in features (such as
bang-searches). They also don't make life hard for Tor users with endless
captcha (there's even an onion service for DDG).

~~~
jaequery
not sure if that still appeals to me.

~~~
dontbenebby
IMHO the bang commands alone make it really useful

[https://duckduckgo.com/bang?q=](https://duckduckgo.com/bang?q=)

------
darkpuma
Is there a way to search for images or videos, e.g. _& iax=images&ia=images_ ?
I looked through the documentation and don't seem to see any.

~~~
apjana
Currently only text search is supported.

~~~
darkpuma
Bummer, I can think of some harmonious interaction between ddgr video search
and youtube-dl. Maybe somebody can put together a PR.

~~~
apjana
You have the option `--url-handler` so the video can be fed to your favorite
media player.

~~~
darkpuma
I'm thinking about invoking from an mpv script with --json.

~~~
apjana
There are some examples in googler's introduction section. Check those out!

------
dontbenebby
Is there a way to supress the search results if I only want an instant answer?

(Ex: If I type in "ip" merely return my IP, not a long list of whois DBs)

~~~
dredmorbius
Instant results are supported:

[https://github.com/jarun/ddgr](https://github.com/jarun/ddgr)

There are a number of "instant" bangs, though it's not clear if these deliver
what you want:
[https://duckduckgo.com/bang?q=instant](https://duckduckgo.com/bang?q=instant)

You can incorporate bang int commandlinee search, though bangs ("!") generally
require quoting to avoid bash / shell interpretation.

~~~
dontbenebby
Ah cool, thanks. Very useful!

I meant more like the various cheatsheets.

(Ex:
[https://duckduckgo.com/?q=vim+cheat+sheet](https://duckduckgo.com/?q=vim+cheat+sheet))

That query would pull up search results, but not the cheat sheet itself. Or if
I do "roll 3 dice" I get unicode dice, but not the numerical sum like on the
web version.

Anyways, this is really a minor gripe - this is a really cool tool and I
appreciate the time you've put into it.

I can see myself using it a lot in the future! :)

------
favadi
Why would I use this if I will need a proper browser to view the result
anyway?

~~~
apjana
Strictly speaking, you don't need a browser. You can directly print the
content of the results in the terminal with the newspaper library.

Coming to the question - the advantage `ddgr` provides is much more
flexibility to the DDG interface or in other words, easy access to parameters
you may want to tweak. For example, show only 10 results per page. Please
check the program options for more.

One can argue, why not use a text browser? Yes, if scrolling around, pressing
tabs to reach a link/field and pressing Enter on it to open the URL/enter text
doesn't bother a user (s)he doesn't need `ddgr`.

------
faissaloo
I find the interface really clunky to use because I need to press enter after
every command.

~~~
smhenderson
I can't tell if you're being sarcastic or not; doesn't that describe just
about everything you do interactively on a command line?

~~~
faissaloo
Yes but the difference is most other programs that employ this interface are
programs I would probably spend alot more time using.

