wmtools/remmina.nim

75 lines
1.9 KiB
Nim
Raw Normal View History

2022-05-10 21:47:15 +02:00
import base
2022-05-10 23:18:37 +02:00
import std/[os,osproc,tables,algorithm]
2022-05-10 21:47:15 +02:00
import configparser
const REMMINA_DIR = getHomeDir() & ".local/share/remmina"
const REMMINA_WS = "4"
2022-05-10 21:47:15 +02:00
var sessions = initTable[string,string]()
var names: seq[string] = @[]
proc main()
proc switchWorkspace() =
if REMMINA_WS != "":
discard execCmd("i3-msg workspace number " & REMMINA_WS)
discard execCmd("swaymsg workspace number " & REMMINA_WS)
2022-05-10 21:47:15 +02:00
proc getRemminaFiles(): seq[string] =
if len(names) < 1:
for file in walkFiles(REMMINA_DIR & "/*.remmina"):
let content = readFile(file)
let ini = parseIni(content)
let group = ini.getProperty("remmina","group")
let name = ini.getProperty("remmina","name")
let server = ini.getProperty("remmina","server")
if name != "" and server != "":
let slug = group & " : " & name & " : (" & server & ")"
sessions[slug] = file
names.add(slug)
names.sort()
return names
proc editRemmina(conn: string) =
let session = sessions[conn]
discard execCmd("remmina -e " & quote(session))
proc startRemmina(conn: string) =
let session = sessions[conn]
discard execCmd("remmina -c " & quote(session))
proc selectRemmina(conn: string) =
var info = newInfo("Remmina : " & conn)
let args = @["connect", "edit", "back"]
let output = outputData(info,args)
if output in args:
case output:
of "connect":
startRemmina(conn)
switchWorkspace()
2022-05-10 21:47:15 +02:00
of "edit":
editRemmina(conn)
switchWorkspace()
2022-05-10 21:47:15 +02:00
of "back":
main()
2022-05-10 21:47:15 +02:00
proc main() =
var info = newInfo("Remmina")
var args: seq[string] = getRemminaFiles()
args.add("new")
args.add("exit")
let output = outputData(info,args)
if output == "exit" or output == "":
return
elif output == "new":
discard execCmd("remmina --new")
elif output in names:
selectRemmina(output)
return
return
if isMainModule:
main()