mirror of
https://github.com/daylinmorgan/tsm.git
synced 2024-12-21 12:50:43 -06:00
refactor: drop cligen and update hwylterm
This commit is contained in:
parent
46d4dfd010
commit
07dd5a5238
6 changed files with 52 additions and 32 deletions
14
nimble.lock
14
nimble.lock
|
@ -1,24 +1,14 @@
|
|||
{
|
||||
"version": 2,
|
||||
"packages": {
|
||||
"cligen": {
|
||||
"version": "1.7.5",
|
||||
"vcsRevision": "85daafd76b0104387f50ff3f75c829b4c2804412",
|
||||
"url": "https://github.com/c-blake/cligen.git",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "f3ffe7329c8db755677d3ca377d02ff176cec8b1"
|
||||
}
|
||||
},
|
||||
"hwylterm": {
|
||||
"version": "0.1.0",
|
||||
"vcsRevision": "c2bcfd1f73dda97bd3e209c89e2abfe588f0977c",
|
||||
"vcsRevision": "337083afe13bf0f1bd024b870c2174a901e8ce06",
|
||||
"url": "https://github.com/daylinmorgan/hwylterm",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "1932229840c893c39acca0b50def19913678f5f0"
|
||||
"sha1": "a995a81f5e4af2991c79ed04b02f17d47dd509e0"
|
||||
}
|
||||
},
|
||||
"illwill": {
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
pname = "tsm";
|
||||
version = "2024.1001-unstable";
|
||||
src = ../.;
|
||||
nimbleDepsHash = "sha256-8noTwYwtaPaF9iGq4EZhWMi709l9e66CJn8vm4aIyO4=";
|
||||
nimbleDepsHash = "sha256-YtW7jv2D/o6z6vgx8cKfqGzs/Yyd6s/Cl5Xs7yavA18=";
|
||||
nimFlags = [
|
||||
"-d:TsmVersion=v${version}"
|
||||
];
|
||||
|
|
|
@ -10,7 +10,7 @@ type
|
|||
open*: bool
|
||||
matched*: bool
|
||||
|
||||
proc pathToName(path: string): string =
|
||||
proc pathToName*(path: string): string =
|
||||
splitPath(path)[1].replace(".", "_")
|
||||
|
||||
proc newProject*(path: string, open: bool, name = "", named: bool = false): Project =
|
||||
|
@ -19,7 +19,7 @@ proc newProject*(path: string, open: bool, name = "", named: bool = false): Proj
|
|||
if name != "":
|
||||
name
|
||||
else:
|
||||
path.pathToName()
|
||||
pathToName(path)
|
||||
result.updated = getLastModificationTime(path)
|
||||
result.open = open
|
||||
result.named = named
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import std/[enumerate, os, strformat, strutils, terminal, sequtils]
|
||||
import std/[enumerate, os, strformat, strutils, terminal]
|
||||
from illwill import illwillDeinit, illwillInit, getKey, Key
|
||||
import term, project
|
||||
|
||||
|
@ -44,7 +44,12 @@ func addDivider(b: var Buffer) =
|
|||
b.addLine "─".repeat(b.width - 2)
|
||||
|
||||
proc addInput(b: var Buffer) =
|
||||
b.addLine "$ " & state.input
|
||||
var line = "$ "
|
||||
if state.input != "":
|
||||
line.add state.input
|
||||
else:
|
||||
line.add $pathToName(getCurrentDir()).bb("faint")
|
||||
b.addLine line
|
||||
|
||||
func numLines(b: Buffer): int =
|
||||
b.buffer.count '\n'
|
||||
|
|
54
src/tsm.nim
54
src/tsm.nim
|
@ -1,6 +1,4 @@
|
|||
import std/[tables]
|
||||
|
||||
import selector, project, tmuxutils
|
||||
import ./[selector, project, tmuxutils]
|
||||
|
||||
# TODO: add option to only opened configured sessions
|
||||
proc tsm(open: bool = false) =
|
||||
|
@ -14,16 +12,44 @@ proc tsm(open: bool = false) =
|
|||
else:
|
||||
tmux.attach project.name
|
||||
|
||||
proc getVersion(): string =
|
||||
const tsmVersion {.strdefine.} = "unknown"
|
||||
const gitVersion = staticExec "git describe --tags --always HEAD --match 'v*'"
|
||||
when tsmVersion != "unknown": tsmVersion
|
||||
else: gitVersion
|
||||
|
||||
|
||||
when isMainModule:
|
||||
import cligen, hwylterm, hwylterm/cli
|
||||
clCfg.version = getVersion()
|
||||
hwylCli(clCfg)
|
||||
let clUse* = $bb("$command $args\n${doc}[bold]Options[/]:\n$options")
|
||||
dispatch(tsm, usage = clUse, short = {"version": 'v'})
|
||||
import std/parseopt
|
||||
import hwylterm, hwylterm/cli
|
||||
|
||||
const tsmVersion {.strdefine.} = staticExec "git describe --tags --always HEAD --match 'v*'"
|
||||
proc help() =
|
||||
echo newHwylCli(
|
||||
"""tmux session manager
|
||||
|
||||
[bold]tsm[/] [[[faint]-h|-v|-o[/]]""",
|
||||
|
||||
flags = [
|
||||
("h","help","show this help"),
|
||||
("v","version", "print version"),
|
||||
("o","open", "only search open sessions")
|
||||
]
|
||||
)
|
||||
var open: bool
|
||||
var p = initOptParser(
|
||||
shortNoVal = {'h', 'v', 'o'},
|
||||
longNoVal = @["open"]
|
||||
)
|
||||
for kind, key, val in p.getOpt():
|
||||
case kind:
|
||||
of cmdEnd:
|
||||
break
|
||||
of cmdArgument:
|
||||
echo bb"[red]Error[/]: unexpected positional argument ", bbfmt"[bold]{key}[/]"
|
||||
of cmdShortOption, cmdLongOption:
|
||||
case key:
|
||||
of "help", "h":
|
||||
help(); quit 0
|
||||
of "version", "v":
|
||||
echo "tsm: " & tsmVersion; quit 0
|
||||
of "open", "o":
|
||||
open = true
|
||||
else:
|
||||
echo bbfmt"[red]Error[/]: unknown key value pair", bbfmt"[b]key[/]: {key}, [b]value[/]: {val}"
|
||||
|
||||
tsm(open)
|
||||
|
|
|
@ -12,7 +12,6 @@ binDir = "bin"
|
|||
|
||||
requires "nim >= 2.0.0"
|
||||
requires "illwill >= 0.4.1"
|
||||
requires "cligen"
|
||||
requires "https://github.com/daylinmorgan/hwylterm#HEAD"
|
||||
requires "https://github.com/usu-dev/usu-nim"
|
||||
|
||||
|
|
Loading…
Reference in a new issue