-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path=
executable file
·49 lines (40 loc) · 1.02 KB
/
=
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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