8000 GitHub - alalik/pycalc: ohmyzsh pycalc plugin - Python‑backed calculator in your Zsh shell.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ pycalc Public

ohmyzsh pycalc plugin - Python‑backed calculator in your Zsh shell.

License

Notifications You must be signed in to change notification settings

alalik/pycalc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pycalc Oh My Zsh Plugin

pycalc turns the = key into a powerful, Python‑backed calculator in your Zsh shell.


Features

  • Basic arithmetic: = 2+24
  • Math functions: All functions from Python’s math module (e.g. ceil, floor, sin, log, etc.)
  • Built-in Python: Access any Python built-in, like round, directly.
  • High-precision decimals: Use the decimal module for arbitrary precision via -d and -p flags.

Installation

Clone the plugin repository and install it into your Oh My Zsh custom plugins directory:

git clone https://github.com/alalik/pycalc.git \
  ~/.oh-my-zsh/plugins/pycalc

Alternatively, download the plugin file directly:

curl -fsSL https://raw.githubusercontent.com/alalik/pycalc/main/pycalc.plugin.zsh \
  -o ~/.oh-my-zsh/plugins/pycalc/pycalc.plugin.zsh

Make sure the file path is ~/.oh-my-zsh/plugins/pycalc/pycalc.plugin.zsh.

  1. Enable the plugin

    • Open your ~/.zshrc in an editor.

    • Find the plugins=(...) line and add pycalc:

      plugins=(git pycalc other-plugins...)
  2. Reload your shell

    exec zsh

Usage

Basic calculation

= 12 * (3 + 4)

Math functions

= ceil(1.2)
= floor(3.8)
= sin(pi/2)
= log(100, 10)

Built-in functions

= round(2.3456, 2)

Decimal precision mode

Use -d to switch to Python’s decimal module. By default, precision is 10 places.

= -d 1/3          # ~0.3333333333 (10 digits)
= -p 4 -d 1/7     # ~0.1429 (4 digits)
  • -d activates decimal mode.
  • -p N sets precision to N digits (default 10).

Help

= -h

Displays:

Usage: = [-h] [-p precision] [-d] expression
  -h   Show this help message
  -p N Set decimal precision to N places
  -d   Use decimal module for high-precision calculations

Examples

Play with basic arithmetic:

= 1+2                     # Addition → 3
= 7-3                     # Subtraction → 4
= 5*6                     # Multiplication → 30
= 20/4                    # Division → 5.0
= 10%3                    # Modulus → 1
= 2**10                   # Exponentiation → 1024
= (3+5)*2                 # Parentheses → 16
= -4+8                    # Negative numbers → 4

Try out a variety of built-in math functions (note the quotes around expressions with commas):

= 2+2                     # Basic arithmetic → 4
= 'ceil(1.2)'             # Ceiling → 2
= 'floor(3.8)'            # Floor → 3
= 'round(2.3456,2)'       # Round to 2 decimals → 2.35
= 'sqrt(16)'              # Square root → 4.0
= 'log(100,10)'           # Log base 10 → 2.0
= 'log10(1000)'           # Log base 10 (alternate) → 3.0
= 'exp(2)'                # e^2 → 7.389056...
= 'sin(pi/2)'             # Sine of 90° → 1.0
= 'cos(pi)'               # Cosine of 180° → -1.0
= 'tan(pi/4)'             # Tangent of 45° → 1.0
= 'factorial(5)'          # 5! → 120
= 'hypot(3,4)'            # sqrt(3^2 + 4^2) → 5.0
= -p 6 -d '22/7'          # Decimal mode with 6-digit precision → 3.142857
= 'pow(2,8)'              # Exponentiation → 256
= 'round(e+pi, 2)'        # Round to 2 decimals → 5.86

Troubleshooting

  • zsh: command not found: =

    • Ensure the plugin file is in ~/.oh-my-zsh/plugins/pycalc/pycalc.plugin.zsh.
    • Confirm pycalc is listed in your plugins=(...) in ~/.zshrc.
    • Reload with exec zsh.
  • Decimal precision doesn’t change

    • Use = -p <N> -d <expression> (order of flags matters: specify -p before -d).
  • Syntax errors

    • Wrap expressions containing spaces or commas in quotes: = 'round(3.1415, 2)'.

License

pycalc is released under the MIT license.

About

ohmyzsh pycalc plugin - Python‑backed calculator in your Zsh shell.

Resources

License

Stars

Watchers

Forks

Languages

0