From bd899ebbf3839c6c6185402c43d60e695194a6f3 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Mon, 9 May 2022 19:56:26 +0100 Subject: [PATCH] added calculate --- README.MD | 1 + calculate.nim | 32 ++++++++++++++++++++++++++++++++ compile_all.sh | 0 fuzzytime.nim | 0 volume.nim | 0 5 files changed, 33 insertions(+) create mode 100644 calculate.nim mode change 100755 => 100644 compile_all.sh mode change 100755 => 100644 fuzzytime.nim mode change 100755 => 100644 volume.nim diff --git a/README.MD b/README.MD index b0620f8..14558ff 100644 --- a/README.MD +++ b/README.MD @@ -15,6 +15,7 @@ which are selectable options in dmenu. - `nic` shows the status and/or the ip address of the network interface card - `temperature` shows the current CPU temperature - `notes` a simple one liner note taking tool, displaying notes in `dmenu`/`rofi` +- `calculate` a calculator, utilising `qalculate` - inspired by [@fedops](https://codeberg.org/fedops/scripts) The next two do not work with `rofi` unless you have `alias dmenu=rofi` set, but they're pretty nice tools diff --git a/calculate.nim b/calculate.nim new file mode 100644 index 0000000..ce692f8 --- /dev/null +++ b/calculate.nim @@ -0,0 +1,32 @@ +import base +import std/[osproc,strutils,sequtils] + +#using qalc as it has a lot of nice inbuilt features +# +proc doCalculation(calc: string) = + var info = newInfo("Calculator") + let ans_cmd_terse = "echo \"" & calc & "\" | qalc +u8 -terse -color=never | awk '!/^>/ && !/^$/ {gsub(/^[ \\t]+|[ \\t]+$/, \"\", $0); print}'" + let ans_cmd_full = "echo \"" & calc & "\" | qalc +u8 -color=never | awk '!/^>/ && !/^$/ {gsub(/^[ \\t]+|[ \\t]+$/, \"\", $0); print}'" + let ans_full = execCmdEx(ans_cmd_full) + let ans_terse = execCmdEx(ans_cmd_terse) + let answers = @[strip(ans_terse.output), + strip(ans_full.output)] + let args = concat(answers,@["exit"]) + let cmd = outputData(info, args) + if cmd in answers: + discard execCmd("echo \"" & strip(cmd) & "\" | xclip") + elif cmd == "exit": + return + else: + doCalculation(cmd) + +proc main() = + var info = newInfo("Calculator") + let args = @["exit"] + let cmd = outputData(info, args) + if cmd != "": + doCalculation(cmd) + return + +if isMainModule: + main() diff --git a/compile_all.sh b/compile_all.sh old mode 100755 new mode 100644 diff --git a/fuzzytime.nim b/fuzzytime.nim old mode 100755 new mode 100644 diff --git a/volume.nim b/volume.nim old mode 100755 new mode 100644