-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd-calc
More file actions
executable file
·39 lines (31 loc) · 795 Bytes
/
d-calc
File metadata and controls
executable file
·39 lines (31 loc) · 795 Bytes
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
#!/usr/bin/env bash
# NOTE : Need package 'bc' to be installed
usage() {
echo " $(tput bold)menu calc$(tput sgr0)
A calculator for use with Rofi or $menu(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/$menu"
exit
}
case $1 in
-h|--help) usage ;;
esac
# Path to menu application
menu="$(command -v $menu) -l 5"
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