{-# LANGUAGE NoMonomorphismRestriction #-} {-# OPTIONS_GHC -Wno-missing-signatures #-} {-# OPTIONS_GHC -Wno-unused-imports #-} module ShellRC where import qualified Control.Lens as L import qualified Data.Aeson as A import qualified Data.Aeson.Key as A import qualified Data.Aeson.KeyMap as A import qualified Data.Aeson.Lens as L import qualified Data.ByteString.Lazy as B import Data.ByteString.Lazy.UTF8 as BLU import qualified Data.ByteString.Lazy.UTF8 as BU import qualified Data.Map as Map import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.Vector as V import qualified Data.Yaml as Y import qualified Data.Yaml.Pretty as Y import Horizon.Spec import Network.HTTP.Simple import Path import Procex.Prelude import Procex.Shell hiding (promptFunction) import System.Directory import System.Environment promptFunction :: [String] -> Int -> IO String promptFunction _modules _line = do d <- getEnv "PWD" setCurrentDirectory d pure $ d <> ": " _init :: IO () _init = do initInteractive getEnv "REALHOME" >>= setEnv "HOME" -- Set by the script that launches GHCi hackagePkg :: Text -> IO A.Value hackagePkg x = do k <- parseRequest $ "http://hackage.haskell.org/package/" <> T.unpack x getResponseBody <$> httpJSON k hackagePkgLatest :: Text -> IO Text hackagePkgLatest x = Prelude.last . Map.keys . A.toMapText . L.view L._Object <$> hackagePkg x runAllFeedback :: IO () runAllFeedback = do (x :: Either Y.ParseException A.Value) <- Y.decodeFileEither "feedback.yaml" t <- getEnv "TERM" let y = Map.keys . A.toMapText . L.view (L._Right . L._Object . L.ix "loops" . L._Object) $ x mapM_ (captureLazyNoThrow . mq t "--command" "nix" "run" "github:NorfairKing/feedback" "--" . T.unpack) y