Integrated command line math
danielcorin.github.io
danielcorin.github.io
An example: http://i.imgur.com/vaN7HfS.png
$ qalc
> 15 kilogram * (4 m/s)^2 / 2
(15 * kilogram * (((4 * meter) / second)^2)) / 2 = 120((kg*m^2) / s^2)
> convert best
120((kg*m^2) / s^2) = 120 J
> convert gTNT
120 J = approx. 28.680688 mgTNT
[0] http://qalculate.sourceforge.net/ echo "$1" | bc -l
No need to rev up python. from math import *
Which gives you significantly more options.I love this idea, I have always found math in the command line to be clunky.
In any case, since I have emacs open all time, I usually do
M-x calc
for one-off calculations. function calc {
print $1 | bc -l
}
Then: calc "(1+2)*3"
9
zsh actually comes with its own little calculator: zcalc "(1+2)*3"
1> 9
2>
Among other things, it features "full command line editing, including the history of previous calculations". $ bc -l <<< 3+2
5
$Actually, perhaps I should write one!
I'll leave implementing it as an exercise to the reader. Personally I have found using Guake (http://guake.org/) with IPython as the shell a very nice way of solving this problem.
For example, my .bash_profile contains:
function scrub { ps -ef |grep $1 | grep -v grep | awk '{print $2}' | xargs kill }
mostly because I was too lazy to install pkill, but I can just do `scrub tomcat` and it works.
Also, don't alias a script path. Just add the script to the path.
qc() { python -c "from math import *; print $@" ; }
directly (or in your .bashrc) from math import *
print '<?xml version="1.0"?><items>'
print '<item uid="qcresult" valid="yes" autocomplete="">'
print '<title>'+str({query})+'</title>'
print '</item></items>' $ echo $((3**5))
243 $ echo $((2 * atan2(1, 0)))
3.14159265358979324 zmodload zsh/mathfunc
_calc() { echo $[$*] }
alias c='noglob _calc'
Then: % c 2 * atan(1, 0)
3.1415926535897931
(Although this works with any command, using an alias with qalc as pointed out above might be more useful.)