1# rofi-calc 2 3** Do live calculations in rofi!** 4 5[![GitHub Actions Workflow](https://github.com/svenstaro/rofi-calc/workflows/Build/badge.svg)](https://github.com/svenstaro/rofi-calc/actions) 6[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/svenstaro/rofi-calc/blob/master/LICENSE) 7[![Stars](https://img.shields.io/github/stars/svenstaro/rofi-calc.svg)](https://github.com/svenstaro/rofi-calc/stargazers) 8 9A [rofi](https://github.com/DaveDavenport/rofi) plugin that uses qalculate's `qalc` to parse natural language input and provide results. 10 11Since 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. 12 13![](demo.gif) 14 15Run rofi like: 16 17 rofi -show calc -modi calc -no-show-match -no-sort 18 19The result of the current input can be selected with `Ctrl+Enter`, and history entries can be selected with `Enter`. By default this will just output the equation/result. 20 21The 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. 22You can disable persistent history if you don't like that. 23 24## Installation 25 26<a href="https://repology.org/project/rofi-calc/versions"><img align="right" src="https://repology.org/badge/vertical-allrepos/rofi-calc.svg" alt="Packaging status"></a> 27 28### Via package manager 29 30* [Arch Linux](https://www.archlinux.org/packages/community/x86_64/rofi-calc/) 31* [FreeBSD](https://www.freshports.org/x11/rofi-calc/) 32* [Gentoo](https://packages.gentoo.org/packages/x11-misc/rofi-calc) 33* [openSUSE](https://software.opensuse.org/package/rofi-calc) 34 35### From source 36 37You need a C compilation toolchain (a `cc`, `autoconf`, `pkg-config`, ...), `rofi` (version >= 1.5) as well as `qalculate` (version > 2.0). 38 39You will also need development headers for `rofi`. Depending on your distribution these may be included in different packages: 40 41* Arch Linux, Gentoo: included with `rofi`, `libqalculate` 42* OpenSUSE: `zypper in rofi rofi-devel qalculate` 43* Debian: `dpkg --install rofi-dev qalc libtool` 44* Ubuntu: `apt install rofi-dev qalc libtool` 45* Solus: `eopkg it rofi-devel libqalculate` 46* CentOS, Fedora: Install `qalculate` (find `rofi-devel` headers yourself) 47* Others: look it up :) 48 49Some distributions ship an [extremely outdated](https://github.com/svenstaro/rofi-calc/issues/7) version of `qalculate` so you might have to compile your own. If that is the case, see [here](https://github.com/svenstaro/rofi-calc/wiki/Installing-libqalculate-from-source). 50 51**rofi-calc** uses autotools as build system. If installing from git, the following steps should install it: 52 53```bash 54$ autoreconf -i 55$ mkdir build 56$ cd build/ 57$ ../configure 58$ make 59$ make install 60``` 61 62## Advanced Usage 63 64- Use the `-qalc-binary` option to specify the name or location of qalculate's `qalc` binary. Defaults to `qalc`. 65- Use the `-terse` option to reduce the output of `qalc` to just the result of the input expression. 66- Use the `-no-unicode` option to disable `qalc`'s Unicode mode. 67- Use the `-calc-command` option to specify a shell command to execute which will be interpolated with the following keys: 68 69 * `{expression}`: the left-side of the equation (currently not available when using `-terse`) 70 * `{result}`: the right of the equation 71 72 The following example copies the result to the clipboard upon pressing the key combination defined by `-kb-accept-custom` 73 (by default Control+Return). 74 NOTE: `{result}` should be quoted since it may contain characters that your shell would otherwise interpret: 75 76 rofi -show calc -modi calc -no-show-match -no-sort -calc-command "echo -n '{result}' | xclip" 77 78- It's convenient to bind it to a key combination in i3. For instance, you could use: 79 80 bindsym $mod+c exec --no-startup-id "rofi -show calc -modi calc -no-show-match -no-sort > /dev/null" 81 82- To disable the bold font applied to the results by default, you can use the flag `-no-bold` and run rofi like: 83 84 rofi -show calc -modi calc -no-show-match -no-sort -no-bold 85 86- To disable persistent history, use `-no-persist-history`: 87 88 rofi -show calc -modi calc -no-show-match -no-sort -no-persist-history 89 90 This will disable writing and loading the history file and thus you'll lose and entered entries 91 upon quitting rofi-calc. 92 93- To disable the history entirely, use `-no-history`: 94 95 rofi -show calc -modi calc -no-show-match -no-sort -no-history -lines 0 96 97 The benefit of this is that you can simply enter a term and press return and that'll already 98 act on the result by printing it to stdout or via `-calc-command` if configured. 99 100- To enable thousand separators in the output (e.g. `5 * 12 = 6,000`, rather than `6000`) add the following to `~/.config/qalculate/qalc.cfg` 101 102 - For `,` separator: 103 104 digit_grouping=2 105 106 - For space separator: 107 108 digit_grouping=1 109 110- To use a different output format for numeric representations (for instance, some locales use `,` instead of `.` as a decimal separator), 111 set `LC_NUMERIC` to a different value like this: 112 113 LC_NUMERIC=de_DE.UTF-8 rofi -show calc -modi calc -no-show-match -no-sort 114 115- To set a different default locale, set your `LC_MONETARY` variable: 116 117 LC_MONETARY=de_DE.UTF-8 rofi -show calc -modi calc -no-show-match -no-sort 118 119 Make sure the locale is actually available on your system! 120 121- Use the `-hint-result` option to specify the text of the hint before result. 122- Use the `-hint-welcome` option to specify the welcome text. 123 124## Development 125 126If you're developing this, it might be helpful to start rofi directly with a locally compiled plugin like this: 127 128 rofi -plugin-path build/.libs -show calc -modi calc -no-show-match -no-sort 129