Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Ddgr – search DuckDuckGo from your terminal (github.com/jarun)
143 points by apjana on April 8, 2019 | hide | past | favorite | 52 comments



Reminds me of surfraw:

https://gitlab.com/surfraw/Surfraw

https://wiki.archlinux.org/index.php/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.


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.


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


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.


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!


Thanks for sharing this.


Just installed it; love it. Will save me time by avoiding the need to switch from terminal to browser to use ddg [and sidesteps the less-than-optimal UI of Lynx, which I still use pretty frequently but dislike for search].

Big up!


Thank you for the compliment!


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

I'm not sure I follow. Is there an option to route this command over Tor? DuckDuckGo has a dot onion but queries on DuckDuckGo.com aren't routed over Tor.


No, it doesn't mean by default routing over Tor. There's an option to specify proxy which you can use to route your ddgr searches using the Tor network. However, Google blocks that.


Google doesn't /block/ Tor, they just make life difficult for users by giving endless captcha depending on what exit node you have (similar to what Cloudflare did until quite recently).

But maybe you're referring to API access? I'm not sure if Tor users are outright blocked (and if the block is any different to other "abusive" IPs).


Please try it out with googler.


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


There's no such hard-coding. For me it opens in w3m. Probably you have BROWSER defined to a GUI browser.


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


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


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


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.


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 :) )


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.


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


I haven't messed with text based browsers for a while - do you have a favorite?


I use w3m all the time.


Thanks I'm going to play around with it a bit.


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


You can. Please use the option `-t`.


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".


Yes, but that's it. No "past year" or custom ranges.


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

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


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


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).


not sure if that still appeals to me.


IMHO the bang commands alone make it really useful

https://duckduckgo.com/bang?q=


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.


Currently only text search is supported.


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


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


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


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


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)


Instant results are supported:

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

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


Ah cool, thanks. Very useful!

I meant more like the various cheatsheets.

(Ex: 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! :)


Try

  ddgr ip --np


Thanks! Looks like

ddgr -n 1 --np ip

gets close

(setting -n to 0 gives a lot of results for some reason?)

Anyways, very small gripe - really like this program. Thanks for your efforts!


n=0 is the default and results in the default behavior - sow all fetched results in the same page.

Thanks for the compliment! Glad to know you like it.

Update: In fact, there was an option and an extra API to fetch only the instant answer. But it seemed like a overkill because the instant answer comes along with the other results. So I removed that additional API a while back.


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


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`.


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


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?


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


I think the primary advantages of something like this is more so that it enables you to use it with terminal tools, and from/in other programs (e.g. calling it from vim). There's also the benefit of increased productivity if you want to stay in terminal. It wasn't designed to to be more ergonomic than the browser based one.


You are right on spot! Couldn't have explained better myself.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: