{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Shellmet
( ($|)
, ($?)
) where
import Control.Exception (catch)
import Data.String (IsString (..))
import Data.Text (Text)
import System.Process (callCommand, readProcess, showCommandForUser)
import qualified Data.Text as T
instance (a ~ [Text], b ~ IO ()) => IsString (a -> b) where
fromString :: String -> [Text] -> IO ()
fromString cmd args = do
let cmdStr = showCommandForUser cmd (map T.unpack args)
putStrLn $ "⚙ " ++ cmdStr
callCommand cmdStr
infix 5 $|
($|) :: FilePath -> [Text] -> IO Text
cmd $| args = T.strip . T.pack <$> readProcess cmd (map T.unpack args) ""
infixl 4 $?
($?) :: IO a -> IO a -> IO a
action $? handler = action `catch` \(_ :: IOError) -> handler