• Stars
    star
    756
  • Rank 60,056 (Top 2 %)
  • Language
    C
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🖩 Do live calculations in 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:

  • Arch Linux, Gentoo: included with rofi, libqalculate
  • OpenSUSE: zypper in rofi rofi-devel qalculate
  • Debian: apt install rofi-dev qalc libtool libtool-bin
  • Ubuntu: apt install rofi-dev qalc libtool
  • Solus: eopkg it rofi-devel libqalculate
  • CentOS, Fedora: Install qalculate automake libtool (find rofi-devel headers yourself)
  • Others: look it up :)

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

  • Use the -qalc-binary option to specify the name or location of qalculate's qalc binary. Defaults to qalc.

  • Use the -terse option to reduce the output of qalc to just the result of the input expression.

  • Use the -no-unicode option to disable qalc's Unicode mode.

  • Use the -calc-command option to specify a shell command to execute which will be interpolated with the following keys:

    • {expression}: the left-side of the equation (currently not available when using -terse)
    • {result}: the right of the equation

    The following example copies the result to the clipboard upon pressing the key combination defined by -kb-accept-custom (by default Control+Return). NOTE: {result} should be quoted since it may contain characters that your shell would otherwise interpret:

      rofi -show calc -modi calc -no-show-match -no-sort -calc-command "echo -n '{result}' | xclip"
    

    Alternatively, this example would immediately type out the result (using xdotool) wherever your cursor currently is (upon pressing Control+Return/-kb-accept-custom):

      rofi -modi calc -show calc -calc-command 'xdotool type --clearmodifiers "{result}"'
    
  • The -calc-command-history option will additionally add the output of qalc to history when the -calc-command is run. This will have no effect if -no-history is enabled.

  • It's convenient to bind it to a key combination in i3. For instance, you could use:

      bindsym $mod+c exec --no-startup-id "rofi -show calc -modi calc -no-show-match -no-sort > /dev/null"
    
  • To disable the bold font applied to the results by default, you can use the flag -no-bold and run rofi like:

      rofi -show calc -modi calc -no-show-match -no-sort -no-bold
    
  • To disable persistent history, use -no-persist-history:

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

    This will disable writing and loading the history file and thus you'll lose and entered entries upon quitting rofi-calc.

  • To disable the history entirely, use -no-history:

      rofi -show calc -modi calc -no-show-match -no-sort -no-history -lines 0
    

    The benefit of this is that you can simply enter a term and press Return and that'll already act on the result by printing it to stdout or via -calc-command if configured.

  • To automatically save last calculation to the history on rofi close, use -automatic-save-to-history.:

      rofi -show calc -modi calc -no-show-match -no-sort -automatic-save-to-history
    

    This means that calculations are put into history even if you don't press Return.

  • To enable thousand separators in the output (e.g. 5 * 12 = 6,000, rather than 6000) add the following to ~/.config/qalculate/qalc.cfg

    • For , separator:

        digit_grouping=2
      
    • For space separator:

        digit_grouping=1
      
  • To use a different output format for numeric representations (for instance, some locales use , instead of . as a decimal separator), set LC_NUMERIC to a different value like this:

      LC_NUMERIC=de_DE.UTF-8 rofi -show calc -modi calc -no-show-match -no-sort
    
  • To set a different default locale, set your LC_MONETARY variable:

      LC_MONETARY=de_DE.UTF-8 rofi -show calc -modi calc -no-show-match -no-sort
    

    Make sure the locale is actually available on your system!

  • Use the -hint-result option to specify the text of the hint before result.

  • Use the -hint-welcome option to specify the welcome text.

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

More Repositories

1

genact

🌀 A nonsense activity generator
Rust
7,449
star
2

miniserve

🌟 For when you really just want to serve some files over HTTP right now!
Rust
4,653
star
3

upload-release-action

Upload files to a GitHub release
TypeScript
429
star
4

cargo-profiler

Cargo subcommand to profile binaries
Rust
426
star
5

rust-web-boilerplate

Rust web template for modern web backend applications
Rust
286
star
6

bvh

A fast BVH using SAH in rust
Rust
226
star
7

wmfocus

Visually focus windows by label
Rust
195
star
8

flamejam

A generic game jam application with ratings and comments using Flask
HTML
140
star
9

memefs

Mount your memes using FUSE
Rust
131
star
10

glsl-language-server

Language server implementation for GLSL
C++
104
star
11

proxyboi

A super simple reverse proxy with TLS support
Rust
81
star
12

dwarf_fortress_unfuck

Unfucking Dwarf Fortress
C++
80
star
13

dummyhttp

Super simple HTTP server that replies a fixed body with a fixed response code
Rust
56
star
14

pseudoform

Pseudoform is a community-driven collaboration project that aims to create an involving and brain-melting first-person puzzle-solving game.
C++
38
star
15

trac0r

A fast real time physically based renderer
C++
29
star
16

upx-action

Strips and runs upx on binaries
JavaScript
25
star
17

mt940-rs

A MT940 parser in Rust
Rust
22
star
18

python-web-boilerplate

Python web template for modern web backend applications
Python
21
star
19

keycloak-http-webhook-provider

A Keycloak provider that posts events to a URL via HTTP POST as JSON
Java
20
star
20

derp

The derp game engine in D
D
20
star
21

gamejam

This is a gamejam project for all kinds of jams.
Lua
19
star
22

wiresmith

Auto-config WireGuard clients into a mesh
Rust
17
star
23

lglive

live.linuX-gamers live gaming distro
Shell
16
star
24

site24x7_exporter

A Prometheus compatible exporter for site24x7.com
Rust
13
star
25

crabcluster

A simple integrated container orchestration solution
Rust
12
star
26

pytest-colordots

Colorizes the progress indicators
Python
12
star
27

dotfiles

Various dotfiles from my machines
Vim Script
12
star
28

minimal-examples

A bunch of small standalone programs
C++
11
star
29

proby

📡 Check whether hosts are reachable on certain ports and return result on HTTP
Rust
10
star
30

playgrounds

Just some playing around with physics.
C++
9
star
31

Spacescape

A space skybox tool using Ogre3D
C++
8
star
32

fints-institute-db

A library and CLI tool to access FinTS access information for many German banks
Rust
6
star
33

talks

Talks for conferences and such
HTML
5
star
34

fints-rs

A compliant FinTS implementation
Rust
5
star
35

vulkanology

Test Vulkan compute shaders using Rust
Rust
5
star
36

qponies

Desktop ponies using qml
C++
5
star
37

NoisyHunter

Implementation of http://www.squidi.net/three/entry.php?id=85
C++
5
star
38

Pseudoform-2

C++
4
star
39

piplayer

Receive a command, play a song
Rust
4
star
40

bankthing

💰 A thing that does stuff with banks
Python
3
star
41

instacheer

Instant cheer for your desktop!
C++
3
star
42

benchy

FOSS cross-platform desktop benchmarking tool
C++
3
star
43

MegaGong

School gong for my class
C++
2
star
44

ilswlol

Wer weiss?
Python
2
star
45

arkenon

Stuff with spaceships
C++
2
star
46

pong4p

4-player multiplayer pong
Python
2
star
47

minitraderoute

A Mini Metro-inspired space trading game
Rust
2
star
48

txt2vid

A text to video renderer
2
star
49

windowcrap

Experimental crap for your desktop!
C++
2
star
50

esp32-toys

Just playing around with ESP32
Python
2
star
51

ssl-proxy-docker

Dockerized version of https://github.com/suyashkumar/ssl-proxy
Dockerfile
2
star
52

rust-web-experiments

Various experiments with rust in the web
Rust
2
star
53

overpower

CLI tool to benchmark web servers with nice output
Rust
2
star
54

rust-timescale-sqlx-rocket

A little integration test of Rust, TimescaleDB, sqlx, and Rocket
Rust
2
star
55

lolpi

A simple implementation of Bellard's formula for calculating PI.
C++
2
star
56

uefi-playground

Experiments with UEFI
Makefile
2
star
57

innojam13

IGJam #13
Rust
1
star
58

cargo-sweb

Simple and convenient cargo subcommand to develop web applications
1
star
59

gameservers

Instant game servers for various games
Shell
1
star
60

taxi-simulation

Schizl
Rust
1
star
61

innojam8

InnoGames Game Jam 8
JavaScript
1
star
62

infinerator

Image generator to generate every possible combination of a given resolution and color depth
C++
1
star
63

pink-fluffy-unicorns

Interactive Visual Computing using POVRay
TeX
1
star
64

qemu-espressif-docker

A container image containing espressif-qemu
Dockerfile
1
star
65

caca

Copy And Convert Audio
Python
1
star
66

fredjam2018

Rust
1
star
67

svenstaro

My GitHub profile page
1
star
68

gamedev-starter-packs

Starter packs for various languages
Lua
1
star
69

docker-archlinux-bootstrap

Arch Linux Docker base image that is generated from the official bootstrap
Shell
1
star
70

epaper-frame

A color e-ink-based picture frame driven by an ESP32
Rust
1
star
71

docker-phoronix-test-suite

A Docker image featuring a ready-to-run installation of the Phoronix Test Suite
Dockerfile
1
star
72

uni-projekt

Projekt Mikrocomputer
Python
1
star
73

rust-python-experiment

Experiments involving Rust + Python
Rust
1
star
74

strapon

Modern C++14 helpers for game stuff
C++
1
star