{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}

module KitsuneBook.Shell where

import Common
import Data.Conduit.Shell as Shell

runIO :: MonadIO m => Segment r -> m r
runIO = liftIO . run

execute :: MonadIO m => Text -> CanonicalPath -> m ()
execute cmd path = runIO . shell . textToString $ cmd'
  where cmd' = cmd ++ " " ++ toText' path

echoLess :: MonadIO m => Text -> m ()
echoLess t = runIO (echo t $| shell "less")

mv :: MonadIO m => FilePath -> FilePath -> m ()
mv p to = runIO $ Shell.mv (toTextUnsafe p) (toTextUnsafe to)

rm :: MonadIO m => FilePath -> m ()
rm p = runIO $ Shell.rm ("-r" :: Text) (toTextUnsafe p)

grep :: MonadIO m => Text -> m ()
grep = runIO . Shell.grep
