Skip to content

Instantly share code, notes, and snippets.

@wader
Created December 28, 2020 12:35
Show Gist options
  • Save wader/31181451b86fab5160b6b7ac4c6612d3 to your computer and use it in GitHub Desktop.
Save wader/31181451b86fab5160b6b7ac4c6612d3 to your computer and use it in GitHub Desktop.
cli calculator with readline, history, decimal, hex, octal, binary and ascii output
# requires rlwrap and iprint
# brew install rlwrap iprint
# apt-get install rlwrap iprint
rlwrap -C calc sh -c '(test $# -gt 0 && echo $* || cat) | while read l ; do n=$(echo $(($l))) && i $n ; done' --
# as bash alias
alias c="rlwrap -C calc sh -c '(test \$# -gt 0 && echo \$* || cat) | while read l ; do n=\$(echo \$((\$l))) && i \$n ; done' --"
# usage
# expr as argument
> c 5+5
10 0xA 012 0b1010 '\n'
# repl
> c
5+5
10 0xA 012 0b1010 '\n'
ctrl-c or ctrl-d to exit
# variables
> c a=5,a+5
10 0xA 012 0b1010 '\n'
# hex literals
> c 0xa+3
13 0xD 015 0b1101 '\r'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment