fix: properly attach to new session

This commit is contained in:
Daylin Morgan 2023-09-30 19:11:50 -05:00
parent 81f7e0b4a8
commit eb97385d9b
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -26,7 +26,7 @@ template cmd(tmux: Tmux, args: string) =
proc newTmux(): Tmux = proc newTmux(): Tmux =
result.active = existsEnv("TMUX") result.active = existsEnv("TMUX")
# check if server is active? # check if server is active?
if execCmd("tmux run") == 0: if execCmdEx("tmux run").exitCode == 0:
result.sessions = ( result.sessions = (
result.cmdGet "list-sessions -F '#S'" result.cmdGet "list-sessions -F '#S'"
).strip().split("\n") ).strip().split("\n")
@ -38,9 +38,11 @@ proc attach*(t: Tmux, session: string) =
t.cmd fmt"{args} {session}" t.cmd fmt"{args} {session}"
proc new*(t: Tmux, session: string, loc: string) = proc new*(t: Tmux, session: string, loc: string) =
let args = if t.active:
if t.active: "new-session -d" t.cmd fmt"new-session -d -s {session} -c {loc}"
else: "new-session" t.attach session
t.cmd fmt"{args} -s {session} -c {loc}" else:
t.cmd fmt"new-session -s {session} -c {loc}"
let tmux* = newTmux() let tmux* = newTmux()