mirror of
https://github.com/daylinmorgan/tsm.git
synced 2024-11-16 09:18:32 -06:00
refactor!: switch from ini to usu
This commit is contained in:
parent
bada89d821
commit
f9ea275eb0
5 changed files with 61 additions and 39 deletions
|
@ -26,6 +26,7 @@ task bundle, "package build assets":
|
|||
exec cmd
|
||||
|
||||
|
||||
|
||||
# begin Nimble config (version 2)
|
||||
--noNimblePath
|
||||
when withDir(thisDir(), system.fileExists("nimble.paths")):
|
||||
|
|
34
nimble.lock
34
nimble.lock
|
@ -1,16 +1,6 @@
|
|||
{
|
||||
"version": 2,
|
||||
"packages": {
|
||||
"bbansi": {
|
||||
"version": "0.1.0",
|
||||
"vcsRevision": "a7eb31407d50bb773bebc8b590ae25fa5af1bbec",
|
||||
"url": "https://github.com/daylinmorgan/bbansi",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "1a4ea3d954edf4d76202237e4848ed56e468a0f2"
|
||||
}
|
||||
},
|
||||
"cligen": {
|
||||
"version": "1.7.0",
|
||||
"vcsRevision": "4193f802796f15559c81c6dd56724d6f20345917",
|
||||
|
@ -23,12 +13,32 @@
|
|||
},
|
||||
"illwill": {
|
||||
"version": "0.3.3",
|
||||
"vcsRevision": "6ba6045038a01d1855208c4a9be7d4826d774001",
|
||||
"vcsRevision": "449ae5d2f05aba125d5a71823ff1da55b1766d70",
|
||||
"url": "https://github.com/inv2004/illwill/",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "c1971885588771d9c413d5b6ade93237e8f1635a"
|
||||
"sha1": "7109f26fc632ceed85e0c48afe55051948c1bc61"
|
||||
}
|
||||
},
|
||||
"bbansi": {
|
||||
"version": "0.1.0",
|
||||
"vcsRevision": "e77ad85cd3a68cabd6ef66727fa1a0cd14c4d0d3",
|
||||
"url": "https://github.com/daylinmorgan/bbansi",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "f47cade0fa02ef944d76e31199762b26389bb9a9"
|
||||
}
|
||||
},
|
||||
"usu": {
|
||||
"version": "0.1.0",
|
||||
"vcsRevision": "25574d165bb7f60900b36590bc49f3d90e47cea4",
|
||||
"url": "https://github.com/usu-dev/usu-nim",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "61a8c13946e3eea9dbe04a6141ed93811563026c"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -2,16 +2,28 @@
|
|||
"depends": [
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"path": "/nix/store/x91md8lmrxxdd4xizg0r9gcbl8sqn8vk-source",
|
||||
"rev": "6ba6045038a01d1855208c4a9be7d4826d774001",
|
||||
"sha256": "13hrcvpynlyr8hqx1h6qkfd32ihg255yd8wmk6l4q6bmiw8frw09",
|
||||
"path": "/nix/store/86prp3nzb853d7isbhgrixw6b8l55gdn-source",
|
||||
"rev": "449ae5d2f05aba125d5a71823ff1da55b1766d70",
|
||||
"sha256": "1vmp1wamfzwcb1rnwvrwsz53sd3k3bqgcpg9c9x29p6q27d1ffdz",
|
||||
"srcDir": "",
|
||||
"url": "https://github.com/inv2004/illwill/archive/6ba6045038a01d1855208c4a9be7d4826d774001.tar.gz",
|
||||
"url": "https://github.com/inv2004/illwill/archive/449ae5d2f05aba125d5a71823ff1da55b1766d70.tar.gz",
|
||||
"subDir": "",
|
||||
"packages": [
|
||||
"illwill"
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"path": "/nix/store/pgajs406yg0ffw099np6fca3psf8zlvr-source",
|
||||
"rev": "25574d165bb7f60900b36590bc49f3d90e47cea4",
|
||||
"sha256": "0qf162bagcgnxjsjpg560cz6kdshhsyrkzq3j471a8pxrhwp608i",
|
||||
"srcDir": "src",
|
||||
"url": "https://github.com/usu-dev/usu-nim/archive/25574d165bb7f60900b36590bc49f3d90e47cea4.tar.gz",
|
||||
"subDir": "",
|
||||
"packages": [
|
||||
"usu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"path": "/nix/store/4h59kkd5db97j5m92szryjydxyr9bnwg-source",
|
||||
|
@ -26,11 +38,11 @@
|
|||
},
|
||||
{
|
||||
"method": "fetchzip",
|
||||
"path": "/nix/store/8ilhirvpc8qi3jbbh1fi3a8psr780cz4-source",
|
||||
"rev": "a7eb31407d50bb773bebc8b590ae25fa5af1bbec",
|
||||
"sha256": "06s4198pbqjga7nqrvajyxqxx3df83fk3qn21pv7axshl19kh9bq",
|
||||
"path": "/nix/store/m086yq0f29cg98w3b12d70cw7xki1j39-source",
|
||||
"rev": "e77ad85cd3a68cabd6ef66727fa1a0cd14c4d0d3",
|
||||
"sha256": "1l5a5kwviq76kxzagljzpwzc3p43qz7wzs5zvrqi5c59klw1967c",
|
||||
"srcDir": "src",
|
||||
"url": "https://github.com/daylinmorgan/bbansi/archive/a7eb31407d50bb773bebc8b590ae25fa5af1bbec.tar.gz",
|
||||
"url": "https://github.com/daylinmorgan/bbansi/archive/e77ad85cd3a68cabd6ef66727fa1a0cd14c4d0d3.tar.gz",
|
||||
"subDir": "",
|
||||
"packages": [
|
||||
"bbansi"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import std/[os, parsecfg, sequtils, tables, strutils]
|
||||
import std/[os, sequtils, tables, strutils]
|
||||
import usu
|
||||
|
||||
import term
|
||||
|
||||
|
@ -10,18 +11,19 @@ type
|
|||
Session = object
|
||||
name*, dir*: string
|
||||
|
||||
# TODO: update when the API for usu is complete
|
||||
proc loadConfigFile(): TsmConfig =
|
||||
let configPath = getHomeDir() / ".config/tsm/config.ini"
|
||||
if configPath.fileExists():
|
||||
let iniTable = loadConfig(configPath)
|
||||
if "sessions" in iniTable:
|
||||
for key, value in iniTable["sessions"].pairs:
|
||||
result.sessions.add Session(name: key, dir: value)
|
||||
if "dirs" in iniTable:
|
||||
for key, value in iniTable["dirs"].pairs:
|
||||
if value != "":
|
||||
termError "[dirs] table should only contain a list of paths"
|
||||
result.dirs.add key
|
||||
let configPath = getConfigDir() / "tsm" / "config.usu"
|
||||
if fileExists configPath:
|
||||
let usuNode = parseUsu(readFile configPath)
|
||||
let topFields = usuNode.fields
|
||||
if "dirs" in topFields:
|
||||
for dir in usuNode.fields["dirs"].elems:
|
||||
result.dirs.add dir.value
|
||||
if "sessions" in topFields:
|
||||
for session in usuNode.fields["sessions"].elems:
|
||||
result.sessions.add Session(name: session.fields["name"].value,
|
||||
dir: session.fields["dir"].value)
|
||||
|
||||
proc loadTsmConfig*(): TsmConfig =
|
||||
result = loadConfigFile()
|
||||
|
@ -30,10 +32,5 @@ proc loadTsmConfig*(): TsmConfig =
|
|||
result.dirs = tsmDirs.split(":")
|
||||
|
||||
when isMainModule:
|
||||
let dict = loadConfig(getHomeDir() / ".config/tsm/config.ini")
|
||||
let sections = dict.sections().toSeq()
|
||||
if "sessions" in sections:
|
||||
for key, value in dict["sessions"].pairs:
|
||||
echo key, value
|
||||
echo loadConfigFile()
|
||||
|
||||
echo loadTsmConfig()
|
||||
|
|
|
@ -11,8 +11,10 @@ binDir = "bin"
|
|||
# Dependencies
|
||||
|
||||
requires "nim >= 2.0.0"
|
||||
requires "https://github.com/inv2004/illwill/#6ba6045038a01d1855208c4a9be7d4826d774001"
|
||||
# illwill PR 47
|
||||
requires "https://github.com/inv2004/illwill/#449ae5d2f05aba125d5a71823ff1da55b1766d70"
|
||||
# requires "illwill == 0.3.2",
|
||||
requires "cligen"
|
||||
requires "https://github.com/daylinmorgan/bbansi >= 0.1.0"
|
||||
requires "https://github.com/usu-dev/usu-nim"
|
||||
|
||||
|
|
Loading…
Reference in a new issue