Discover, install, and configure shell plugins with Fig Plugin Store ā†’
šŸ§®

Calc Plugin for Zsh

zsh calculator - with support for basic math

arzzen
|
123 stars
7 forks

Simple zsh calculator

This is a calculator which runs on zsh.

Demo

calc demo

Usage

# addition
[email protected]:~$ = 5+3
8

# multiplication
[email protected]:~$ = '4*2'
8

# subtraction
[email protected]:~$ = -4-2
-6

# division
[email protected]:~$ = 5.0/2
2.5

# square root
[email protected]:~$ = sqrt(2)
1.41421

# parentheses
[email protected]:~$ = "(6+6)*6"
72

# convert from decimal to hexadecimal
[email protected]:~$ = "[#16] 255"
16#FF

# convert from decimal to binary
[email protected]:~$ = "[#2] 12"
2#1100

# convert from binary to decimal
[email protected]:~$ = "2#1100"
12

# convert from hexadecimal to decimal
[email protected]:~$ = "16#FF"
255

# arctangent
[email protected]:~$ = atan(1)
.785398

# PI value
[email protected]:~$ = PI
3.14159

# more complex
[email protected]:~$ = "3.4+7/8-(5.94*(4*atan(1)))"
-15.2611

Alternative Implementations

# Put these in your .zshrc (No need to install a plugin)
cc() python3 -c "from math import *; print($*);"
alias cc='noglob cc'
# You can use `cc` just like `=` from above. All functions from the math module of Python are available for use. 

Plugin location

.oh-my-zsh
ā””ā”€ā”€ā”€ plugins/
     ā””ā”€ā”€ā”€ calc/
          ā””ā”€ā”€ā”€ calc.plugin.zsh