Lurker News

Comments (85) 22 threads

nathancahill#
Nice catch, updated to the new API.
AlphaWeaver1 reply#
Instructions are also included to use DuckDuckGo.
jxy#
Wonderful. I decided to put a script together.

  #!/bin/bash
  S="$(echo "$@" | sed -E 's, +,+,g')"
  g(){
   curl -sS "https://suggestqueries.google.com/complete/search?client=firefox&q=$1" \
    | sed -E 's,.*\[([^]]*)\].*,\1,;s,",,g' | tr , '\n'
  }
  d(){
   curl -sS "https://duckduckgo.com/ac/?q=$1" \
    | sed -E 's,"phrase":|[][{}"],,g' | tr , '\n'
  }
  paste -d , <(g $S) <(d $S) | column -t -s ,
jxy3 replies#
If you have your shell ready,

    curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' \
        | json_pp | sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'
devoply1 reply#
I have learned the hard way never to type stuff like this into a shell because I might not like the results. It looks fine, but never again. ;)
curiousgal2 replies#
What happened?
devoply#
This was like 13 years ago, but it in essence rm -rvf / ... but it was a obfuscated one liner that some dick put out there as a joke. Result was having to restore a site and lose a few weeks of posts.
verandaguy11 replies#
It's generally an easy way to introduce malicious shell scripts into remote machines operated by people who don't know about this.

There's a blog dedicated to shaming sites that do this: https://curlpipesh.tumblr.com/#_=_

Continue this thread — 11 replies

jsrn2 replies#
Nice!

To run this with macOS, I had to use the GNU version of sed. I installed it with

    $ brew install gnu-sed
And it is then called with 'gsed' instead of 'sed'.

As an avid Perl programmer, I had json_pp in my $PATH - for everyone else - it is here: https://metacpan.org/pod/JSON::PP
You can install it with cpanm:

    $ cpanm JSON::PP
If you don't have cpanm, you can install it with

    $ curl -L https://cpanmin.us | perl - App::cpanminus
The modified command line from above then becomes:

    $ curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' \
        | json_pp | gsed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'
Here is a little Bash function to encapsulate this:

    $ function c() { curl -sS "https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=$1" | json_pp | gsed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'; }
Which then allows you to use it like this:

    $ c hacker
    hacker news
    hacker typer
    hackerrank
    hackerman
    hackers movie
    hacker fare
    hackerone
    hackers cast
    hacker pschorr
For spaces in your query, use a '+':

    $ c New+York
    new york times
    new york and company
    new york giants
    new york post
    new york daily news
    new york weather
eridius#
You can use BSD sed by just inserting a semicolon into the sed pattern:

  sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p;}'
(Edited to remove previous advice about inserting a newline)
ekns#
Improved version using jq. This properly URL encodes the query parameter and uses a much simpler sed command. Additionally the API returns UTF-8 encoded data when the user agent is specified. Requires curl >= 7.18.0.

    function c() {
        url='https://www.google.com/complete/search?client=hp&hl=en&xhr=t'
        # NB: user-agent must be specified to get back UTF-8 data!
        curl -H 'user-agent: Mozilla/5.0' -sSG --data-urlencode "q=$*" "$url" |
            jq -r .[1][][0] |
            sed 's,,,g'
    }
Example:

    $ c ':)' ':('
    ) ( meaning
    ) ( emoticon
    ) ( ͡° ͜ʖ ͡°)
    ) ( emoticon meaning
jsrn2 replies#
Here is the command with jq instead of json_pp

    $ curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' | jq . | gsed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p}'
(see my other comment about gsed vs sed)
eridius#
Here's the above modified to work with BSD sed:

  curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' | jq . | sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p;}'
(Edited to remove previous advice about inserting a newline)
kevinastone#
You don't need sed, you can do it all in jq:

    curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' | jq -r '.[1] | .[][0] | sub(""; ""; "gi")'
meowzerus839#
Had this idea a while back: I really enjoyed auto complete in my IDE and configurable expansions and I wanted that everywhere. I threw together an app to run in the background to keep track of the last word I typed and manage suggestions when I hit a hotkey. Read from a local dictionary, used basic usage frequency and levenshtein distance to recommend, pretty straightforward hacked together in an afternoon project. I could see Anycomplete using a more local suggestion list instead of relying on Google.

Ideally it showed a drop down under where you're typing much like most IDEs would, but support was shotty at best. I really wish there were more OS level hooks for this sort of thing, or a more standardized way to understand what the user is typing and where, but that's not something I ever expect to happen. My app was basically a keylogger while the one in the post is more like a separate entity altogether.

lbotos4 replies#
I just tried Hammerspoon for the first time this week and it's really, really powerful. Currently working on an automation suite for a bunch of tedious "micro-workflows" that I deal with on a daily basis.
meowzerus8391 reply#
For windows users, I recommend AutoHotkey
curiousgal3 replies#
Are there decent Linux alternatives?
pbhjpbhj1 reply#
Isn't Autohotkey just echoing a text or running a script for an associated key combination? KDE has that built in (I think they call it khotkeys?). I'd be surprised if other DEs don't have similar?

IIRC Autohotkey makes an application from your hotkey choice that you then run (eg via autostart or using an icon) to instate the hotkey afresh every reboot.
To this end it seemed inferior to the KDE equivalent for me, but that could just be familiarity bias.

Continue this thread — 1 reply

_vya71 reply#
Really enjoying seeing a lot of new projects based on Hammerspoon. And very glad for the people who created it, because maintaining the precursor was a daunting job and took too much of my time and gave me too much stress.
nathancahill#
Thanks for starting Mjolnir though!
ryanSrich2 replies#
Is there a place to find inspiration or other examples of Hammerspoon extensions? Just installed and wrote a few simple scripts, but having a hard time coming up with anything groundbreaking that I'd want to build.
weitzj#
Check out the Hammerspoon Wiki on Github
lbotos#
I'm currently automating any workflow that I use daily:

- We have a team call and a team agenda doc, I'm using a hotkey to open a chooser, which has an option "goto team call" that fires up the call window and the doc.
- We deal with prod/dev so I made another item in the chooser "log in to dev server" which opens a chrome incognito window, presses the one password unlock shortcut and then I'm just waiting there to input 2 factor.
As I uncover more of these, I'll be coding them up and using the master chooser to deal with any annoying workflows. :)

wingerlang#
Have you tried Keyboard Maestro?

Load more comments