]>
Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/gxpr
2 # Usage: gxpr <expression>
3 # Like expr(1), but uses Google's calculator to evaluate <expression>.
12 # $ gxpr '(2 ^ 1) + (2 ^ 2) + (2 ^ 3) + (2 ^ 5)'
15 # $ gxpr '5*9+(sqrt 10)^3='
18 # Conversion examples:
22 # $ gxpr 10 megabits in megabytes
25 # $ gxpr 2 miles in inches
28 CURL
='curl -s --header User-Agent:gxpr/1.0'
29 SEARCH
="http://www.google.com/search"
30 EXPR
=$(echo "$@" | sed -e 's/+/%2B/g' -e 's/ /+/g')
33 $CURL "$SEARCH?q=$EXPR" |
35 perl
-pe 's@.*<h2 class=r.*?<b>.*?= (.*?)</b>.*@\1@' |
36 perl
-pe 's@\x{a0}@@g' |
37 perl
-pe 's@ </font>@@g' |
41 # if we don't have a result, assume it's an invalid expression
43 echo "invalid expression:" "$@" 1>&2