390 points · by nathancahill · 9y ago · 85 comments
[0]: http://stackoverflow.com/questions/6428502/google-search-aut... [1]: https://webmasters.googleblog.com/2015/07/update-on-autocomp...
#!/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 , 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}'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 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,</\?b>,,g'
}
Example: $ c ':)' ':('
) ( meaning
) ( emoticon
) ( ͡° ͜ʖ ͡°)
) ( emoticon meaning sed -nE '/<\/?b>/{s```g;s`"|,|^ *``g;p;}'
(Edited to remove previous advice about inserting a newline) $ 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) curl -sS 'https://www.google.com/complete/search?client=hp&hl=en&xhr=t&q=aurora' | jq -r '.[1] | .[][0] | sub("</?b>"; ""; "gi")' 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)There's a blog dedicated to shaming sites that do this: https://curlpipesh.tumblr.com/#_=_
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.
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.
- 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. :)
Universal autocomplete via google api? Hmm, something to think about.
1) Keyloggers
2) Filter bubbles
3) Offline tax
Related, reminds me of the havoc you could wreck on phpBB boards with [you] command enabled. For those who haven't seen it, a [you] BBcode is replaced on display with viewing user's name.
So you'd generally write a reasonably sounding comment, with a sentence like "This is something [you] was supposed to do.", you'd post it and then it was time to eat popcorn.
Search for "swing", then in the search box, delete that and type in "play". It'll auto-complete with something like "playground swing".
Now in a new tab, search for "music". Then delete that and search for "play". You'll get different results.
(doesn't work with the browser search box, has to be the one in the page itself)
[edit] Actually, I guess the way you described it, it could go the other way. You start writing some argument, and google shows you some stats that show you're wrong, or something. That would be neat.
[0]: https://github.com/nathancahill/anycomplete/blob/master/anyc...
FTFY