svenstaro / rofi-calc

🖩 Do live calculations in rofi!
MIT License
964 stars 31 forks source link
calculate calculator rofi

rofi-calc

🖩 Do live calculations in rofi!

GitHub Actions Workflow license Stars

A rofi plugin that uses qalculate's qalc to parse natural language input and provide results.

Since this uses qalculate's amazing qalc you can try natural language queries such 500 + 25% or 5000 EUR to USD or 150 to hex. It can also solve linear equations on the fly. Try 60x + 30 = 50, for instance.

Run rofi like:

rofi -show calc -modi calc -no-show-match -no-sort

The result of the current input can be selected with Ctrl+Return, and history entries can be selected with Return. By default this will just output the equation/result.

The history file by default sits at $HOME/.local/share/rofi/rofi_calc_history in case you ever need to delete it or change it manually. You can disable persistent history if you don't like that.

Installation

Packaging status

Via package manager

From source

You need a C compilation toolchain (a cc, autoconf, pkg-config, ...), rofi (version >= 1.5) as well as qalculate (version > 2.0).

You will also need development headers for rofi. Depending on your distribution these may be included in different packages:

Some distributions ship an extremely outdated version of qalculate so you might have to compile your own. If that is the case, see here.

rofi-calc uses autotools as build system. If installing from git, the following steps should install it:

$ git clone https://github.com/svenstaro/rofi-calc.git
$ cd rofi-calc/
$ mkdir m4
$ autoreconf -i
$ mkdir build
$ cd build/
$ ../configure
$ make
# make install

Advanced Usage

Custom Rofi Theme compatibility

If you are using a custom theme with rofi (e.g. rofi -show drun -theme ~/.config/rofi/mytheme.rasi) and don't see the result of the calculation, that's because the rofi-calc mode relies on the message widget that might be hidden by some themes.

In your mytheme.rasi file or any file, it might @import, look for the following

mainbox {
    children: [...]
}

make sure the list contains message
for example

mainbox {
    children: [inputbar, message, listview]
}

Reference Rofi docs: Layout, Base Widgets, Children

Development

If you're developing this, it might be helpful to start rofi directly with a locally compiled plugin like this:

autoreconf -i
mkdir build
cd build
../configure
make
rofi -plugin-path .libs -show calc -modi calc -no-show-match -no-sort