Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
Prepare first release
Browse files Browse the repository at this point in the history
  • Loading branch information
ckrybus committed Apr 30, 2022
1 parent f5adbc4 commit 065b00f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Unreleased


## v0.1.0 (2022-05-01)

* Initial release
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 [Christoph Krybus](mailto:ckrybus@googlemail.com)
Copyright (c) 2020-2022 [Christoph Krybus](mailto:chris@ckrybus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
lint:
nimpretty src/*.nim

build:
nim c --styleCheck:hint src/*.nim

release:
nim -d:release --opt:size --passL:-s c src/yakuakep.nim
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ sudo apt-get install qdbus-qt5

## Features

- display yakuake tabs
- save yakuake tabs to a json file
- restore yakuake tabs from a json file
- [x] display yakuake tabs
- [x] save yakuake tabs to a json file
- [ ] (TODO) restore yakuake tabs from a json file

## Usage

Expand All @@ -29,7 +29,6 @@ For now only a very basic interface exists
```bash
$ yakuakep ps # show all tabs
$ yakuake save # save tabs
$ yakuake load # load previously saved tabs
```

## Limitations
Expand All @@ -45,4 +44,3 @@ Welcome❤
## License

MIT License. Please see [License File](LICENSE) for more information.

21 changes: 10 additions & 11 deletions src/yakuakep.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import osproc, strutils, strformat, algorithm, cligen, terminaltables, os, sequtils, json
import osproc, strutils, strformat, algorithm, cligen, terminaltables, os,
sequtils, json


proc run(cmd: string): string =
Expand Down Expand Up @@ -32,27 +33,25 @@ proc getCmd(pid: int, fgpid: int): string =
return ""


iterator getSessionData(): Tab =
iterator getTabs(): Tab =
for i, _ in dbusMany(fmt"/yakuake/sessions sessionIdList"):
# in yakuake you can have multiple terminals per tab
# yakuakep currently supports only one terminal per tab
var sessionId = dbus(fmt"/yakuake/tabs sessionAtTab {i}")
var terminalIdsRaw = dbusMany(fmt"/yakuake/sessions terminalIdsForSessionId {session_id}")

var terminalIdsRaw = dbusMany(fmt"/yakuake/sessions terminalIdsForSessionId {session_id}")
# TODO how to sort by int in nim?
var terminalIds = newSeq[int](0)
for x in terminalIdsRaw:
terminalIds.add(x.parseInt)
terminalIds.sort()
var terminalId = terminalIds[0]

var title = dbus(fmt"/yakuake/tabs tabTitle {sessionId}")
var sid = terminalId + 1
var pid = dbus(fmt"/Sessions/{sid} processId").parseInt
var fgpid = dbus(fmt"/Sessions/{sid} foregroundProcessId").parseInt
var command = getCmd(pid, fgpid)
var workingDirectory = getPwd(pid)

yield Tab(command: command, workingDirectory: workingDirectory, title: title)


Expand All @@ -69,7 +68,7 @@ proc ps() =
## Show yakuake session
var table = newTerminalTable()
table.setHeaders(@["TITLE", "WORKING DIRECTORY", "COMMAND"])
for tab in getSessionData():
for tab in getTabs():
table.addRow(@[tab.title, tab.workingDirectory, tab.command])
printTable(table)
discard
Expand All @@ -79,18 +78,18 @@ proc save() =
## Save yakuake session to a file
let configDirPath = joinPath(getConfigDir(), "yakuakep")
discard existsOrCreateDir(configDirPath)
let tabs = toSeq(getSessionData())
let tabs = toSeq(getTabs())
let filepath = joinPath(configDirPath, "default.json")
writeFile(filepath, $(pretty(%*tabs)))
echo(fmt"Yakuake tabs saved successfully to {filepath}")
discard


proc load() =
## Load yakuake session from a file
echo "TODO load"
proc restore() =
## Restore yakuake session from a file
echo "TODO restore"
discard


when isMainModule:
dispatchMulti([ps], [save], [load])
dispatchMulti([ps], [save], [restore])

0 comments on commit 065b00f

Please sign in to comment.