1
- import osproc, strutils, strformat, algorithm, cligen, terminaltables, os, sequtils, json
1
+ import osproc, strutils, strformat, algorithm, cligen, terminaltables, os,
2
+ sequtils, json
2
3
3
4
4
5
proc run (cmd: string ): string =
@@ -32,27 +33,25 @@ proc getCmd(pid: int, fgpid: int): string =
32
33
return " "
33
34
34
35
35
- iterator getSessionData (): Tab =
36
+ iterator getTabs (): Tab =
36
37
for i, _ in dbusMany (fmt" /yakuake/sessions sessionIdList " ):
37
38
# in yakuake you can have multiple terminals per tab
38
39
# yakuakep currently supports only one terminal per tab
39
40
var sessionId = dbus (fmt" /yakuake/tabs sessionAtTab { i} " )
40
- var terminalIdsRaw = dbusMany (fmt" /yakuake/sessions terminalIdsForSessionId { session_id} " )
41
41
42
+ var terminalIdsRaw = dbusMany (fmt" /yakuake/sessions terminalIdsForSessionId { session_id} " )
42
43
# TODO how to sort by int in nim?
43
44
var terminalIds = newSeq [int ](0 )
44
45
for x in terminalIdsRaw:
45
46
terminalIds.add (x.parseInt)
46
47
terminalIds.sort ()
47
48
var terminalId = terminalIds[0 ]
48
-
49
49
var title = dbus (fmt" /yakuake/tabs tabTitle { sessionId} " )
50
50
var sid = terminalId + 1
51
51
var pid = dbus (fmt" /Sessions/{ sid} processId " ).parseInt
52
52
var fgpid = dbus (fmt" /Sessions/{ sid} foregroundProcessId " ).parseInt
53
53
var command = getCmd (pid, fgpid)
54
54
var workingDirectory = getPwd (pid)
55
-
56
55
yield Tab (command: command, workingDirectory: workingDirectory, title: title)
57
56
58
57
@@ -69,7 +68,7 @@ proc ps() =
69
68
# # Show yakuake session
70
69
var table = newTerminalTable ()
71
70
table.setHeaders (@ [" TITLE" , " WORKING DIRECTORY" , " COMMAND" ])
72
- for tab in getSessionData ():
71
+ for tab in getTabs ():
73
72
table.addRow (@ [tab.title, tab.workingDirectory, tab.command])
74
73
printTable (table)
75
74
discard
@@ -79,18 +78,18 @@ proc save() =
79
78
# # Save yakuake session to a file
80
79
let configDirPath = joinPath (getConfigDir (), " yakuakep" )
81
80
discard existsOrCreateDir (configDirPath)
82
- let tabs = toSeq (getSessionData ())
81
+ let tabs = toSeq (getTabs ())
83
82
let filepath = joinPath (configDirPath, " default.json" )
84
83
writeFile (filepath, $ (pretty (%* tabs)))
85
84
echo (fmt" Yakuake tabs saved successfully to { filepath} " )
86
85
discard
87
86
88
87
89
- proc load () =
90
- # # Load yakuake session from a file
91
- echo " TODO load "
88
+ proc restore () =
89
+ # # Restore yakuake session from a file
90
+ echo " TODO restore "
92
91
discard
93
92
94
93
95
94
when isMainModule :
96
- dispatchMulti ([ps], [save], [load ])
95
+ dispatchMulti ([ps], [save], [restore ])
0 commit comments