Don't attach to a session if we're already in one

This commit is contained in:
Daniel Harvey 2020-03-17 16:37:29 +00:00
parent 21234d47fb
commit c55c3ab264
2 changed files with 16 additions and 1 deletions

View File

@ -6,6 +6,7 @@ module TmuxMate.TmuxCommands
createWindow,
removeWindowPanes,
removeWindows,
attachToSession,
getTmuxCommands,
)
where
@ -41,7 +42,7 @@ getTmuxCommands sesh tmuxState =
then removeAdminPane sTitle
else []
)
<> [AttachToSession sTitle]
<> (attachToSession sTitle runningInTmux)
-- create a new session if required
createSession :: InTmuxSession -> ValidatedSession -> [VSessionName] -> [TmuxCommand]
@ -206,3 +207,8 @@ removeWindows inTmux seshName running' windows =
removeAdminPane :: VSessionName -> [TmuxCommand]
removeAdminPane seshName = pure (KillAdminPane seshName)
-- don't attach to session if we're in a session
attachToSession :: VSessionName -> InTmuxSession -> [TmuxCommand]
attachToSession _ (InTmuxSession _) = []
attachToSession sTitle _ = [AttachToSession sTitle]

View File

@ -266,3 +266,12 @@ spec = do
)
]
`shouldBe` []
describe "Attach to session" $ do
it "Should attach to session if we're not in one" $ do
let sessionName' = VSessionName (NE.fromList "session")
attachToSession sessionName' NotInTmuxSession
`shouldBe` [AttachToSession sessionName']
it "Should not attach to session if we're already in one" $ do
let sessionName' = VSessionName (NE.fromList "session")
attachToSession sessionName' (InTmuxSession sessionName')
`shouldBe` []