diff --git a/parser-typechecker/src/Unison/Codebase/Editor/Git.hs b/parser-typechecker/src/Unison/Codebase/Editor/Git.hs index 6ac22e2dbc..d1ab8e71ff 100644 --- a/parser-typechecker/src/Unison/Codebase/Editor/Git.hs +++ b/parser-typechecker/src/Unison/Codebase/Editor/Git.hs @@ -24,7 +24,6 @@ import Control.Monad.Except (MonadError, throwError) import qualified Data.ByteString.Base16 as ByteString import qualified Data.Char as Char import qualified Data.Text as Text -import Shellmet (($?), ($^), ($|)) import System.Exit (ExitCode (ExitSuccess)) import System.FilePath (()) import System.IO.Unsafe (unsafePerformIO) @@ -307,3 +306,38 @@ gitTextIn :: MonadIO m => GitRepo -> [Text] -> m Text gitTextIn localPath args = do when debugGit $ traceM (Text.unpack . Text.unwords $ ["$ git"] <> setupGitDir localPath <> args) liftIO $ "git" $| setupGitDir localPath <> args + +-- copying the Shellmet API for now; we can rename or change it up later + +{- | This operator runs shell command with given options but doesn't print the +command itself. +>>> "echo" $^ ["Foo", "Bar"] +Foo Bar +-} +infix 5 $^ +($^) :: MonadIO m => FilePath -> [Text] -> m () +cmd $^ args = UnliftIO.callProcess cmd (map Text.unpack args) + +{- | Run shell command with given options and return stripped stdout of the +executed command. +>>> "echo" $| ["Foo", "Bar"] +"Foo Bar" +-} +infix 5 $| +($|) :: MonadIO m => FilePath -> [Text] -> m Text +cmd $| args = post <$> UnliftIO.readProcess cmd (map Text.unpack args) stdin + where + stdin = "" + post = Text.strip . Text.pack + +{- | Do some IO actions when process failed with 'IOError'. +>>> "exit" ["0"] $? putStrLn "Command failed" +⚙ exit 0 +>>> "exit" ["1"] $? putStrLn "Command failed" +⚙ exit 1 +Command failed +-} +infixl 4 $? +($?) :: IO a -> IO a -> IO a +action $? handler = action `UnliftIO.catch` \(_ :: IOError) -> handler +{-# INLINE ($?) #-}