From 30acbd67364225a6d9107bdc1be44fb31069f496 Mon Sep 17 00:00:00 2001 From: therbron Date: Wed, 8 Jul 2020 16:15:06 +0200 Subject: [PATCH] Add calculator shortcut for i3 --- .config/calc/= | 49 +++++++++++++++++++++++++++++++++++++++++++++++ .config/i3/config | 3 +++ 2 files changed, 52 insertions(+) create mode 100755 .config/calc/= diff --git a/.config/calc/= b/.config/calc/= new file mode 100755 index 0000000..6c895fa --- /dev/null +++ b/.config/calc/= @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# https://github.com/onespaceman/menu-calc +# Calculator for use with rofi/dmenu(2) +# Copying to the clipboard requires xclip + +usage() { + echo " $(tput bold)menu calc$(tput sgr0) + A calculator for use with Rofi or dmenu(2) + Basic usage: + = 4+2 + = (4+2)/(4+3) + = 4^2 + = sqrt(4) + = c(2) + + The answer can be used for further calculations + + The expression may need quotation marks if + launched outside of Rofi/dmenu" + exit +} + +case $1 in + -h|--help) usage ;; +esac + +# Path to menu application +if [[ -n $(command -v rofi) ]]; then + menu="$(command -v rofi) -dmenu" +elif [[ -n $(command -v dmenu) ]]; then + menu="$(command -v dmenu)" +else + echo >&2 "Rofi or dmenu not found" + exit +fi + +answer=$(echo "$@" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') + +action=$(echo -e "Copy to clipboard\nClear\nClose" | +$menu -p "= $answer") + +case $action in + "Clear") $0 ;; + "Copy to clipboard") echo -n "$answer" | xclip ;; + "Close") ;; + "") ;; + *) $0 "$answer $action" ;; +esac diff --git a/.config/i3/config b/.config/i3/config index d87ab52..d94f78f 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -115,6 +115,9 @@ bindsym $mod+Shift+question exec --no-startup-id $i3-wm.program.help set_from_resource $i3-wm.program.file_search i3-wm.program.file_search rofi -show find -modi find:/usr/share/rofi/modi/finder.sh bindsym $mod+$alt+space exec $i3-wm.program.file_search +## Launch // Calculator inside of rofi +bindsym $mod+equal exec ~/.config/calc/= + ############################################################################### # Window and Workspace Navigation ###############################################################################