Add calculator shortcut for i3

This commit is contained in:
Tanguy Herbron 2020-07-08 16:15:06 +02:00
parent 5e64d20f22
commit 30acbd6736
2 changed files with 52 additions and 0 deletions

49
.config/calc/= Executable file
View File

@ -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

View File

@ -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 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 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 # Window and Workspace Navigation
############################################################################### ###############################################################################