tsm/src/tsm.nim

46 lines
1.2 KiB
Nim
Raw Normal View History

2023-09-05 13:36:33 -05:00
import std/[os, osproc, strformat, tables]
import tui, project
proc checkExe(names: varargs[string]) =
for name in names:
if findExe(name) == "":
echo "tsm requires " & name
2023-09-05 17:02:08 -05:00
template tmux(cmd: string) =
discard execCmd("tmux " & cmd)
2023-09-05 13:36:33 -05:00
proc tsm() =
checkExe "tmux"
let
project = selectProject()
selected = project.name
if existsEnv("TMUX"):
if selected notin listTmuxSessions():
2023-09-05 17:02:08 -05:00
tmux &"new-session -d -s {selected} -c {project.location}"
else:
tmux &"switch-client -t {selected}"
2023-09-05 13:36:33 -05:00
else:
if selected notin listTmuxSessions():
2023-09-05 17:02:08 -05:00
tmux &"new-session -s {selected} -c {project.location}"
2023-09-05 13:36:33 -05:00
else:
2023-09-05 17:02:08 -05:00
tmux &"attach -t {selected}"
2023-09-05 13:36:33 -05:00
when isMainModule:
import cligen
const vsn = staticExec "git describe --tags --always HEAD"
clCfg.version = vsn
if clCfg.helpAttr.len == 0:
clCfg.helpAttr = {"cmd": "\e[1;36m", "clDescrip": "", "clDflVal": "\e[33m",
"clOptKeys": "\e[32m", "clValType": "\e[31m", "args": "\e[3m"}.toTable
clCfg.helpAttrOff = {"cmd": "\e[m", "clDescrip": "\e[m", "clDflVal": "\e[m",
"clOptKeys": "\e[m", "clValType": "\e[m", "args": "\e[m"}.toTable
dispatch(
tsm,
short = {"version": 'v'},
)