wmtools/remmina.nim

66 lines
1.6 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"
var sessions = initTable[string,string]()
var names: seq[string] = @[]
proc main()
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)
of "edit":
editRemmina(conn)
of "back":
main()
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()