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
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 '+':