gregwebs / Shelly.hs

Haskell shell scripting
BSD 3-Clause "New" or "Revised" License
418 stars 88 forks source link

Add withTmpFile? #134

Open kaizhang opened 7 years ago

kaizhang commented 7 years ago
  1. Shelly doesn't have withTmpFile, which is a very useful function.
  2. withTmpDir should be able to create tmp dir under a specific location, like mktempdir does in Turtle.

Any particular reason for not having these?

andreasabel commented 1 year ago

There is https://hackage.haskell.org/package/temporary-1.3/docs/System-IO-Temp.html#v:withTempFile

withTempFile :: (MonadIO m, MonadMask m) =>
                FilePath -- ^ Parent directory to create the file in
             -> String   -- ^ File name template
             -> (FilePath -> Handle -> m a) -- ^ Callback that can use the file
             -> m a

This requires a MonadMask Sh instance which we might not have: https://hackage.haskell.org/package/exceptions-0.10.0/docs/Control-Monad-Catch.html#t:MonadMask

A similar function is in https://hackage.haskell.org/package/unliftio-0.2.23.0/docs/UnliftIO-Temporary.html#v:withTempFile which requires instance MonadUnliftIO Sh.

Maybe it is possible to define one of these instances for Sh?