added calculate
This commit is contained in:
parent
16a2cbade7
commit
bd899ebbf3
5 changed files with 33 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
32
calculate.nim
Normal file
32
calculate.nim
Normal file
|
@ -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()
|
0
compile_all.sh
Executable file → Normal file
0
compile_all.sh
Executable file → Normal file
0
fuzzytime.nim
Executable file → Normal file
0
fuzzytime.nim
Executable file → Normal file
0
volume.nim
Executable file → Normal file
0
volume.nim
Executable file → Normal file
Loading…
Reference in a new issue