Created
August 28, 2015 10:57
-
-
Save epsilonhalbe/a3db218005936ff99d63 to your computer and use it in GitHub Desktop.
Turtle Script for linking ghc from HVRs repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: lnghc | |
version: 0.1.0.0 | |
synopsis: easily change ghc-versions for hvr's ppa repository | |
license: BSD3 | |
license-file: LICENSE | |
author: Martin Heuschober (TSA) | |
maintainer: [email protected] | |
copyright: 2015 Martin Heuschober | |
category: Console App | |
build-type: Simple | |
-- extra-source-files: | |
cabal-version: >=1.22 | |
executable lnghc | |
hs-source-dirs: app | |
main-is: Main.hs | |
ghc-options: -threaded -rtsopts -with-rtsopts=-N | |
build-depends: base >= 4.7 && < 5 | |
, turtle | |
, foldl | |
, text | |
, system-filepath | |
default-language: Haskell2010 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Turtle | |
import Prelude hiding (FilePath) | |
import Data.Either (rights) | |
import qualified Control.Foldl as F | |
import qualified Data.Text as T | |
import Data.Text() | |
main :: IO () | |
main = sh $ do | |
args <- arguments | |
available_ghcs <- map filename <$> (fold (ls "/opt/ghc/") F.list) | |
Just home <- need "HOME" | |
case args of | |
(a:_) -> if (fromText a) `elem` available_ghcs | |
then do _ <- unlink $ home <> "/bin/ghc" | |
_ <- symlink ("/opt/ghc/" <> a <> "/bin") $ home <> "/bin/ghc" | |
echo $ "...successfully changed GHC ["<>a<>"]" | |
else do echo $ "'"<> a <>"' is no valid GHC version" | |
list available_ghcs | |
_ -> do echo "USAGE: lnghc ${GHC VERSION}" | |
list available_ghcs | |
where unlink trgt = proc "unlink" [trgt] "" | |
symlink src trgt = proc "ln" ["-s",src,trgt] "" | |
list :: [FilePath] -> Shell () | |
list versions = do current_ghc <- lastMay . T.words <$> inproc "ghc" ["--version"] "" | |
echo "available GHC versions: " | |
mapM_ (echo . highlight current_ghc) $ rights $ map toText versions | |
highlight :: Maybe Text -> Text -> Text | |
highlight hi str = if hi == Just str | |
then "[" <> str <> "]" | |
else " " <> str <> " " | |
lastMay :: [a] -> Maybe a | |
lastMay [] = Nothing | |
lastMay xx = Just $ last xx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment