This uses the Google Autocomplete API which seems a bit risky to use [0] and according to this Google blog post should be already shut down [1].
Do you have any newer information on how reliable the API is?
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,</\?b>,,g'
}
Example:
$ c ':)' ':('
) ( meaning
) ( emoticon
) ( ͡° ͜ʖ ͡°)
) ( emoticon meaning
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.
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.
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.
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.
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. :)
[0]: http://stackoverflow.com/questions/6428502/google-search-aut... [1]: https://webmasters.googleblog.com/2015/07/update-on-autocomp...
Deleted Comment
To run this with macOS, I had to use the GNU version of sed. I installed it with
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:
If you don't have cpanm, you can install it with The modified command line from above then becomes: Here is a little Bash function to encapsulate this: Which then allows you to use it like this: For spaces in your query, use a '+':[0]: https://stedolan.github.io/jq/
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.
- 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. :)
[1] http://keypirinha.com/
Universal autocomplete via google api? Hmm, something to think about.
1) Keyloggers
2) Filter bubbles
3) Offline tax