From 3aa9fb9490426c1d60b93c888026a7a67cb53046 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 18 Dec 2024 15:58:52 -0600 Subject: [PATCH] add support for opening session in current directory --- src/tsm.nim | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/tsm.nim b/src/tsm.nim index 452f229..7d66fd6 100644 --- a/src/tsm.nim +++ b/src/tsm.nim @@ -1,14 +1,9 @@ -import std/sequtils -import ./[selector, project, tmuxutils] +import std/[sequtils, os] +import ./[selector, project, tmuxutils, term] import hwylterm, hwylterm/hwylcli -proc tsm(open: bool = false) = - let - projects = findProjects(open) - project = selectProject projects - selected = project.name - - if selected notin tmux.sessions.mapIt(it.name): +proc tsm(project: Project) = + if project.name notin tmux.sessions.mapIt(it.name): tmux.new(project.name, project.location) else: tmux.attach project.name @@ -20,7 +15,23 @@ hwylCli: name "tsm" V tsmVersion flags: - open "only search open sessions" + open: + ? "only search open sessions" + - o + new: + ? "open session in current directory" + - n run: - tsm(open) + if new and open: + termQuit "--new and --open are mutually exclusive" + + let project = + if new: newProject( + path = getCurrentDir(), + open = false, + ) + else: + selectProject findProjects(open) + + tsm(project)