mirror of
https://github.com/danieljharvey/tmux-mate.git
synced 2024-08-16 19:50:23 +03:00
tmux-mate init command (#25)
* Init command * Default to tmux-mate.dhall if nothing else passed * Start command * Update readme
This commit is contained in:
parent
fa1d8637ed
commit
126ce037f8
@ -18,6 +18,15 @@ brew update && brew install danieljharvey/tools/tmux-mate
|
|||||||
|
|
||||||
Binaries available on the [releases](https://github.com/danieljharvey/tmux-mate/releases) page.
|
Binaries available on the [releases](https://github.com/danieljharvey/tmux-mate/releases) page.
|
||||||
|
|
||||||
|
### Getting started
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# create a default tmux-mate.dhall
|
||||||
|
tmux-mate init
|
||||||
|
# Start running everything
|
||||||
|
tmux-mate start
|
||||||
|
```
|
||||||
|
|
||||||
### Tutorial
|
### Tutorial
|
||||||
|
|
||||||
Let's grab a couple of sample config files...
|
Let's grab a couple of sample config files...
|
||||||
|
7
app/CLICommands.hs
Normal file
7
app/CLICommands.hs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module CLICommands where
|
||||||
|
|
||||||
|
import TmuxMate (CLIOptions (..))
|
||||||
|
|
||||||
|
data CLICommand
|
||||||
|
= CLIRun CLIOptions
|
||||||
|
| CLIInit
|
35
app/Main.hs
35
app/Main.hs
@ -1,29 +1,20 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Options.Applicative
|
import CLICommands
|
||||||
|
import Options (command)
|
||||||
|
import qualified Options.Applicative as Opt
|
||||||
import System.Exit
|
import System.Exit
|
||||||
import TmuxMate
|
import TmuxMate
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
options' <- execParser (info options fullDesc)
|
command' <- Opt.execParser (Opt.info command Opt.fullDesc)
|
||||||
didItWork <- loadTestSession options'
|
case command' of
|
||||||
case didItWork of
|
CLIInit -> do
|
||||||
Yeah -> exitWith ExitSuccess
|
createTmuxMateDhall
|
||||||
Nah i -> exitWith (ExitFailure i)
|
putStrLn "Initial tmux-mate.dhall created!"
|
||||||
|
CLIRun options' -> do
|
||||||
configFilePathParser :: Parser ConfigFilePath
|
didItWork <- loadTestSession options'
|
||||||
configFilePathParser =
|
case didItWork of
|
||||||
ConfigFilePath
|
Yeah -> exitWith ExitSuccess
|
||||||
<$> argument str (metavar "<path-to-config-file>")
|
Nah i -> exitWith (ExitFailure i)
|
||||||
|
|
||||||
verbosityParser :: Parser Verbosity
|
|
||||||
verbosityParser =
|
|
||||||
flag' Chatty (short 'v' <> long "verbose")
|
|
||||||
<|> flag' DryRun (short 'd' <> long "dry-run")
|
|
||||||
<|> pure Silent
|
|
||||||
|
|
||||||
options :: Parser CLIOptions
|
|
||||||
options =
|
|
||||||
CLIOptions
|
|
||||||
<$> configFilePathParser <*> verbosityParser
|
|
||||||
|
46
app/Options.hs
Normal file
46
app/Options.hs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
module Options (command) where
|
||||||
|
|
||||||
|
import CLICommands
|
||||||
|
import Options.Applicative ((<|>))
|
||||||
|
import qualified Options.Applicative as Opt
|
||||||
|
import TmuxMate
|
||||||
|
|
||||||
|
command :: Opt.Parser CLICommand
|
||||||
|
command =
|
||||||
|
otherCommands
|
||||||
|
<|> (CLIRun <$> options)
|
||||||
|
|
||||||
|
configFilePathParser :: Opt.Parser (Maybe ConfigFilePath)
|
||||||
|
configFilePathParser =
|
||||||
|
( Just <$> ConfigFilePath
|
||||||
|
<$> Opt.argument Opt.str (Opt.metavar "<path-to-config-file>")
|
||||||
|
)
|
||||||
|
<|> pure Nothing
|
||||||
|
|
||||||
|
verbosityParser :: Opt.Parser Verbosity
|
||||||
|
verbosityParser =
|
||||||
|
Opt.flag' Chatty (Opt.short 'v' <> Opt.long "verbose")
|
||||||
|
<|> Opt.flag' DryRun (Opt.short 'd' <> Opt.long "dry-run")
|
||||||
|
<|> pure Silent
|
||||||
|
|
||||||
|
options :: Opt.Parser CLIOptions
|
||||||
|
options =
|
||||||
|
CLIOptions
|
||||||
|
<$> configFilePathParser <*> verbosityParser
|
||||||
|
|
||||||
|
otherCommands :: Opt.Parser CLICommand
|
||||||
|
otherCommands =
|
||||||
|
Opt.subparser
|
||||||
|
( Opt.command
|
||||||
|
"init"
|
||||||
|
( Opt.info
|
||||||
|
(pure CLIInit)
|
||||||
|
(Opt.progDesc "Initialise a new tmux-mate.dhall file")
|
||||||
|
)
|
||||||
|
<> Opt.command
|
||||||
|
"start"
|
||||||
|
( Opt.info
|
||||||
|
(CLIRun <$> options)
|
||||||
|
(Opt.progDesc "Start running everything in the selected config file")
|
||||||
|
)
|
||||||
|
)
|
@ -7,12 +7,15 @@ module TmuxMate
|
|||||||
CLIOptions (..),
|
CLIOptions (..),
|
||||||
ConfigFilePath (..),
|
ConfigFilePath (..),
|
||||||
Verbosity (..),
|
Verbosity (..),
|
||||||
|
createTmuxMateDhall,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
import Data.Maybe (fromMaybe)
|
||||||
import qualified Dhall as Dhall
|
import qualified Dhall as Dhall
|
||||||
import System.Process
|
import System.Process
|
||||||
import TmuxMate.Commands
|
import TmuxMate.Commands
|
||||||
|
import TmuxMate.Init
|
||||||
import TmuxMate.Logger
|
import TmuxMate.Logger
|
||||||
import TmuxMate.Running
|
import TmuxMate.Running
|
||||||
import TmuxMate.TmuxCommands
|
import TmuxMate.TmuxCommands
|
||||||
@ -36,7 +39,7 @@ data DidItWork
|
|||||||
loadTestSession :: CLIOptions -> IO DidItWork
|
loadTestSession :: CLIOptions -> IO DidItWork
|
||||||
loadTestSession options = do
|
loadTestSession options = do
|
||||||
let (decoder :: Dhall.Decoder Session) = Dhall.auto
|
let (decoder :: Dhall.Decoder Session) = Dhall.auto
|
||||||
let path = getConfigFilePath $ configFilePath options
|
let path = fromMaybe "tmux-mate.dhall" (getConfigFilePath <$> configFilePath options)
|
||||||
myLog = logger (verbosity options)
|
myLog = logger (verbosity options)
|
||||||
config <- Dhall.detailed (Dhall.inputFile decoder path)
|
config <- Dhall.detailed (Dhall.inputFile decoder path)
|
||||||
case parseSession config of
|
case parseSession config of
|
||||||
|
37
src/TmuxMate/Init.hs
Normal file
37
src/TmuxMate/Init.hs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
module TmuxMate.Init (createTmuxMateDhall) where
|
||||||
|
|
||||||
|
-- where we make a new empty session file
|
||||||
|
|
||||||
|
import Data.Text.IO
|
||||||
|
import Dhall
|
||||||
|
import Dhall.Core (pretty)
|
||||||
|
import TmuxMate.Types
|
||||||
|
( Pane (..),
|
||||||
|
PaneArrangement (..),
|
||||||
|
PaneCommand (..),
|
||||||
|
Session (..),
|
||||||
|
SessionName (..),
|
||||||
|
Window (..),
|
||||||
|
WindowName (..),
|
||||||
|
)
|
||||||
|
|
||||||
|
createTmuxMateDhall :: IO ()
|
||||||
|
createTmuxMateDhall = do
|
||||||
|
let dhallVal = pretty (embed inject defaultSession)
|
||||||
|
Data.Text.IO.writeFile "./tmux-mate.dhall" dhallVal
|
||||||
|
|
||||||
|
defaultSession :: Session
|
||||||
|
defaultSession =
|
||||||
|
Session
|
||||||
|
(SessionName "tmux-mate")
|
||||||
|
[ Window
|
||||||
|
(WindowName "first")
|
||||||
|
[ Pane
|
||||||
|
( PaneCommand "watch echo \"hello from tmux-mate\""
|
||||||
|
),
|
||||||
|
Pane
|
||||||
|
( PaneCommand "watch echo \"hello again from tmux-mate\""
|
||||||
|
)
|
||||||
|
]
|
||||||
|
(PaneArrangement "tiled")
|
||||||
|
]
|
@ -166,7 +166,7 @@ newtype ConfigFilePath
|
|||||||
|
|
||||||
data CLIOptions
|
data CLIOptions
|
||||||
= CLIOptions
|
= CLIOptions
|
||||||
{ configFilePath :: ConfigFilePath,
|
{ configFilePath :: Maybe ConfigFilePath,
|
||||||
verbosity :: Verbosity
|
verbosity :: Verbosity
|
||||||
}
|
}
|
||||||
deriving (Eq, Ord, Show)
|
deriving (Eq, Ord, Show)
|
||||||
|
Loading…
Reference in New Issue
Block a user