Skip to content

Open-Technology-Foundation/bcx

Repository files navigation

bcx

Terminal calculator for floating-point expressions with interactive REPL

A Bash wrapper around bc that fixes its poor terminal UX by providing readline history, proper Ctrl-C handling, and a clean REPL interface.

GitHub: Open-Technology-Foundation/bcx

Features

  • Interactive REPL with readline history (arrow keys, Ctrl-R search)
  • Single-expression mode for quick calculations
  • Persistent command history (~/.bcx_history)
  • x → * conversion in terminal mode (e.g., 3x4 becomes 3*4)
  • Clean error handling with clear feedback
  • Math library support (sqrt, sin, cos, etc.)

Installation

# Copy to system path
sudo cp bcx /usr/local/bin/
sudo chmod +x /usr/local/bin/bcx

# Optional: Install bash completion
sudo cp .bash_completion /etc/bash_completion.d/bcx

# Optional: Create alias for quick access
echo "alias ?='bcx'" >> ~/.bashrc

Usage

Single-expression evaluation:

bcx "3.14 * 2"              # 6.28
bcx "sqrt(144)"             # 12
bcx 42x72/3.14              # x converts to * in terminal mode

Interactive REPL:

$ bcx
> 2 + 2
4
> sqrt(16)
4
> ^D

As command alias:

? 23x42                     # Quick calculation
? "scale=4; 22/7"           # Pi approximation

In scripts (non-terminal mode):

result=$(bcx "42 * 72 / 3.14")
echo "Result: $result"

Requirements

  • Bash 4.0+
  • bc command-line calculator
  • Linux/Unix terminal with readline support

BCS Compliance

This script follows the Bash Coding Standard with proper error handling, readonly constants, and structured organization.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

GNU General Public License v3.0 - see LICENSE.

Author

Gary Dean | garydean.id

About

Terminal calculator for floating-point expressions with interactive REPL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages