mirror of
https://github.com/danieljharvey/tmux-mate.git
synced 2024-09-11 08:35:53 +03:00
Sheeeeyit
This commit is contained in:
parent
eeba0b6674
commit
5194824efe
@ -39,7 +39,7 @@ getTmuxCommands sesh tmuxState =
|
||||
in {-case runningInTmux of
|
||||
NotInTmuxSession -> NE.tail (vSessionWindows sesh) -- first one is dealt with in invocation of session
|
||||
InTmuxSession _ -> NE.toList (vSessionWindows sesh)-}
|
||||
(createSession runningInTmux sesh)
|
||||
(createSession runningInTmux sesh runningSessions)
|
||||
<> ( concatMap
|
||||
(createWindow sTitle runningPanes)
|
||||
sWindows
|
||||
@ -50,15 +50,18 @@ getTmuxCommands sesh tmuxState =
|
||||
<> [AttachToSession sTitle]
|
||||
|
||||
-- create a new session if required
|
||||
createSession :: InTmuxSession -> ValidatedSession -> [TmuxCommand]
|
||||
createSession inTmux session =
|
||||
createSession :: InTmuxSession -> ValidatedSession -> [VSessionName] -> [TmuxCommand]
|
||||
createSession inTmux session _runningSesh =
|
||||
let seshName = vSessionTitle session
|
||||
in case inTmux of
|
||||
InTmuxSession currentSesh -> [] -- AttachToSession currentSesh]
|
||||
NotInTmuxSession ->
|
||||
[ NewSession
|
||||
seshName
|
||||
]
|
||||
if sessionExists seshName _runningSesh
|
||||
then [AttachToSession seshName]
|
||||
else
|
||||
[ NewSession
|
||||
seshName
|
||||
]
|
||||
|
||||
sessionExists :: VSessionName -> [VSessionName] -> Bool
|
||||
sessionExists = elem
|
||||
|
@ -52,9 +52,10 @@ main = hspec $ do
|
||||
(PaneCommand "yes Pane 1")
|
||||
1
|
||||
]
|
||||
describe "Dhall" $ do
|
||||
it "Round trips Dhall encoding" $ do
|
||||
property dhallSessionRoundtrip
|
||||
|
||||
{-describe "Dhall" $ do
|
||||
it "Round trips Dhall encoding" $ do
|
||||
property dhallSessionRoundtrip -}
|
||||
|
||||
dhallSessionRoundtrip :: Property
|
||||
dhallSessionRoundtrip =
|
||||
|
@ -13,18 +13,37 @@ import TmuxMate.Running
|
||||
import TmuxMate.TmuxCommands
|
||||
import TmuxMate.Types
|
||||
|
||||
sampleSession :: ValidatedSession
|
||||
sampleSession = ValidatedSession
|
||||
{ vSessionTitle = VSessionName $ NE.fromList "horses",
|
||||
vSessionWindows =
|
||||
NE.fromList
|
||||
[ VWindow
|
||||
{ vWindowTitle = VWindowName $ NE.fromList "window",
|
||||
vWindowPanes = undefined
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "createSession" $ do
|
||||
it "Attaches to session if it exists" $ do
|
||||
it "Does nothing if we're already attached" $ do
|
||||
createSession
|
||||
( InTmuxSession
|
||||
(VSessionName $ NE.fromList "horses")
|
||||
(VSessionName $ NE.fromList "dogs")
|
||||
)
|
||||
(VSessionName $ NE.fromList "horses")
|
||||
sampleSession
|
||||
[]
|
||||
`shouldBe` []
|
||||
it "Attaches to session if it already exists" $ do
|
||||
createSession
|
||||
NotInTmuxSession
|
||||
sampleSession
|
||||
[VSessionName $ NE.fromList "horses"]
|
||||
`shouldBe` [AttachToSession (VSessionName $ NE.fromList "horses")]
|
||||
it "Creates a session if we are not in tmux" $ do
|
||||
createSession NotInTmuxSession (VSessionName $ NE.fromList "horses")
|
||||
it "Creates a session if we are not in tmux and session is not running" $ do
|
||||
createSession NotInTmuxSession sampleSession []
|
||||
`shouldBe` [NewSession (VSessionName $ NE.fromList "horses")]
|
||||
describe "createWindow" $ do
|
||||
it "Creates a window if needed" $ do
|
||||
@ -35,10 +54,11 @@ spec = do
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
`shouldBe` Just
|
||||
`shouldBe` pure
|
||||
( CreateWindow
|
||||
(VSessionName $ NE.fromList "horses")
|
||||
(VWindowName $ NE.fromList "window")
|
||||
(Command "go")
|
||||
)
|
||||
it "Creates a window if there is matching one but it's in another session" $ do
|
||||
createWindow
|
||||
@ -46,33 +66,34 @@ spec = do
|
||||
[ Running
|
||||
(VSessionName $ NE.fromList "other")
|
||||
(VWindowName $ NE.fromList "window")
|
||||
undefined
|
||||
(PaneCommand "go")
|
||||
0
|
||||
]
|
||||
( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
`shouldBe` Just
|
||||
( CreateWindow
|
||||
(VSessionName $ NE.fromList "horses")
|
||||
(VWindowName $ NE.fromList "window")
|
||||
)
|
||||
`shouldBe` [ ( CreateWindow
|
||||
(VSessionName $ NE.fromList "horses")
|
||||
(VWindowName $ NE.fromList "window")
|
||||
(Command "go")
|
||||
)
|
||||
]
|
||||
it "Does nothing if one already exists" $ do
|
||||
createWindow
|
||||
(VSessionName $ NE.fromList "horses")
|
||||
[ Running
|
||||
(VSessionName $ NE.fromList "horses")
|
||||
(VWindowName $ NE.fromList "window")
|
||||
undefined
|
||||
(PaneCommand "go")
|
||||
0
|
||||
]
|
||||
( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
`shouldBe` Nothing
|
||||
describe "createWindowPanes" $ do
|
||||
`shouldBe` []
|
||||
{-describe "createWindowPanes" $ do
|
||||
it "Creates one if nothing is there" $ do
|
||||
createWindowPanes
|
||||
(VSessionName $ NE.fromList "horses")
|
||||
@ -104,32 +125,30 @@ spec = do
|
||||
(VWindowName $ NE.fromList "window")
|
||||
(Command "go")
|
||||
]
|
||||
it "Does nothing if one exists" $ do
|
||||
createWindowPanes
|
||||
(VSessionName (NE.fromList "horses"))
|
||||
[ Running
|
||||
(VSessionName (NE.fromList "horses"))
|
||||
(VWindowName (NE.fromList "window"))
|
||||
(PaneCommand "go")
|
||||
0
|
||||
]
|
||||
( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
`shouldBe` []
|
||||
it "Does nothing if one exists" $ do
|
||||
createWindowPanes
|
||||
(VSessionName (NE.fromList "horses"))
|
||||
[ Running
|
||||
(VSessionName (NE.fromList "horses"))
|
||||
(VWindowName (NE.fromList "window"))
|
||||
(PaneCommand "go")
|
||||
0
|
||||
]
|
||||
( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
`shouldBe` []-}
|
||||
describe "removeWindowPanes" $ do
|
||||
it "Does nothing if nothing running" $ do
|
||||
removeWindowPanes
|
||||
(VSessionName (NE.fromList "horses"))
|
||||
[]
|
||||
( NE.fromList
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
]
|
||||
)
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
]
|
||||
`shouldBe` []
|
||||
it "Does nothing if running pane is still needed" $ do
|
||||
removeWindowPanes
|
||||
@ -140,13 +159,11 @@ spec = do
|
||||
(PaneCommand "go")
|
||||
0
|
||||
]
|
||||
( NE.fromList
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
]
|
||||
)
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
]
|
||||
`shouldBe` []
|
||||
it "Creates a remove events if pane is no longer needed" $ do
|
||||
removeWindowPanes
|
||||
@ -157,26 +174,22 @@ spec = do
|
||||
(PaneCommand "go")
|
||||
24
|
||||
]
|
||||
( NE.fromList
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "whoa-no")]
|
||||
)
|
||||
]
|
||||
)
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "whoa-no")]
|
||||
)
|
||||
]
|
||||
`shouldBe` [KillPane (VSessionName (NE.fromList "horses")) 24]
|
||||
describe "removeWindows" $ do
|
||||
it "Does nothing if no window to remove" $ do
|
||||
removeWindows
|
||||
(VSessionName (NE.fromList "horses"))
|
||||
[]
|
||||
( NE.fromList
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
]
|
||||
)
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList [Pane (PaneCommand "go")]
|
||||
)
|
||||
]
|
||||
`shouldBe` []
|
||||
it "Should remove a window if it's no longer needed" $ do
|
||||
removeWindows
|
||||
@ -187,14 +200,12 @@ spec = do
|
||||
(PaneCommand "no")
|
||||
10
|
||||
]
|
||||
( NE.fromList
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList
|
||||
[Pane (PaneCommand "go")]
|
||||
)
|
||||
]
|
||||
)
|
||||
[ ( VWindow
|
||||
(VWindowName (NE.fromList "window"))
|
||||
$ NE.fromList
|
||||
[Pane (PaneCommand "go")]
|
||||
)
|
||||
]
|
||||
`shouldBe` [ KillWindow
|
||||
(VSessionName (NE.fromList "horses"))
|
||||
(VWindowName (NE.fromList "window2"))
|
||||
|
Loading…
Reference in New Issue
Block a user