├── = ├── LICENSE └── README.md /=: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # https://github.com/onespaceman/menu-calc 4 | # Calculator for use with rofi/dmenu(2) 5 | # Copying to the clipboard requires xclip 6 | 7 | usage() { 8 | echo " $(tput bold)menu calc$(tput sgr0) 9 | A calculator for use with Rofi or dmenu(2) 10 | Basic usage: 11 | = 4+2 12 | = (4+2)/(4+3) 13 | = 4^2 14 | = sqrt(4) 15 | = c(2) 16 | 17 | The answer can be used for further calculations 18 | 19 | The expression may need quotation marks if 20 | launched outside of Rofi/dmenu" 21 | exit 22 | } 23 | 24 | case $1 in 25 | -h|--help) usage ;; 26 | esac 27 | 28 | # Path to menu application 29 | if [[ -n $(command -v rofi) ]]; then 30 | menu="$(command -v rofi) -dmenu" 31 | elif [[ -n $(command -v dmenu) ]]; then 32 | menu="$(command -v dmenu)" 33 | else 34 | echo >&2 "Rofi or dmenu not found" 35 | exit 36 | fi 37 | 38 | answer=$(echo "$@" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') 39 | 40 | action=$(echo -e "Copy to clipboard\nClear\nClose" | 41 | $menu -p "= $answer") 42 | 43 | case $action in 44 | "Clear") $0 ;; 45 | "Copy to clipboard") echo -n "$answer" | xclip ;; 46 | "Close") ;; 47 | "") ;; 48 | *) $0 "$answer $action" ;; 49 | esac 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # menu calc 2 | Calculator for Rofi/dmenu(2) 3 | [Screencast](https://gfycat.com/SociableDopeyHerald) 4 | 5 | #####usage: 6 | menu calc uses bc as the backend and will accept any operations bc is able to do 7 | `= -h` show help 8 | `= 4+4` 9 | `= (4+2)/(4+3)` 10 | `= 4^2` 11 | `= sqrt(4)` 12 | `= c(2)` 13 | 14 | The answer can me used for further calculations inside Rofi/dmenu 15 | 16 | If launched outside of Rofi/dmenu the expression may need quotation marks 17 | 18 | #####dependencies 19 | bc 20 | xclip 21 | Rofi or dmenu(2) 22 | --------------------------------------------------------------------------------