refactor: use template

This commit is contained in:
Daylin Morgan 2023-09-05 17:02:08 -05:00
parent 4633b5b01c
commit c5a8923118
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -7,6 +7,9 @@ proc checkExe(names: varargs[string]) =
if findExe(name) == "":
echo "tsm requires " & name
template tmux(cmd: string) =
discard execCmd("tmux " & cmd)
proc tsm() =
checkExe "tmux"
@ -14,16 +17,16 @@ proc tsm() =
project = selectProject()
selected = project.name
# TODO: refactor
if existsEnv("TMUX"):
if selected notin listTmuxSessions():
discard execCmd(&"tmux new-session -d -s {selected} -c {project.location}")
discard execCmd(&"tmux switch-client -t {selected}")
tmux &"new-session -d -s {selected} -c {project.location}"
else:
tmux &"switch-client -t {selected}"
else:
if selected notin listTmuxSessions():
discard execCmd(&"tmux new-session -s {selected} -c {project.location}")
tmux &"new-session -s {selected} -c {project.location}"
else:
discard execCmd(&"tmux attach -t {selected}")
tmux &"attach -t {selected}"
when isMainModule:
import cligen