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