Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of using Turtle
#!/usr/bin/env stack
-- stack runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text.IO as T
import Turtle
exists :: MonadIO io => Text -> io Bool
exists cmd = do
retval <- proc "which" ["-s", cmd] stdin
case retval of
ExitSuccess -> return True
(ExitFailure _) -> return False
brew :: MonadIO io => [Text] -> io ()
brew cmds = void $ proc "brew" cmds stdin
cask :: MonadIO io => [Text] -> io ()
cask cmds = void $ proc "brew" ("cask" : cmds) stdin
say :: MonadIO io => Text -> Text -> io ()
say voice text = void $ proc "say" ["-v", voice, text] stdin
main = do
brew ["tap", "caskroom/cask"]
-- Password is required for the first cask command.
say "Ting-Ting" "需要输入密码"
sequence $ fmap installApp apps
return ()
where
apps = [ "sublime-text"
, "spectacle"
, "google-chrome"
, "firefox"
, "docker"
] :: [Text]
installApp app = do
T.putStrLn $ "Installing cask " <> app <> "..."
cask ["install", app]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment