Skip to content

Instantly share code, notes, and snippets.

@notcome
Created March 26, 2018 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notcome/b93b8ad21667271f9fc78918803bf1ef to your computer and use it in GitHub Desktop.
Save notcome/b93b8ad21667271f9fc78918803bf1ef to your computer and use it in GitHub Desktop.
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