REF undo homegrown pipe command

This commit is contained in:
Nathan Dwarshuis 2023-01-02 22:20:43 -05:00
parent f0451891b8
commit f95079ba5e
1 changed files with 24 additions and 28 deletions

View File

@ -22,13 +22,9 @@ where
import RIO
import qualified RIO.Text as T
import System.IO hiding (hSetBuffering)
import System.Posix.IO
import System.Posix.Process
import qualified System.Process.Typed as P
import qualified XMonad.Core as X
-- import qualified XMonad.Util.Run as XR
import qualified XMonad.Util.Run as XR
-- | Fork a new process and wait for its exit code.
--
@ -93,30 +89,30 @@ spawnPipe
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
=> T.Text
-> m Handle
spawnPipe = spawnPipeRW
spawnPipe = liftIO . XR.spawnPipe . T.unpack
spawnPipeRW
:: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
=> T.Text
-> m Handle
spawnPipeRW x = do
(r, h) <- liftIO mkPipe
child r
liftIO $ closeFd r
return h
where
mkPipe = do
(r, w) <- createPipe
setFdOption w CloseOnExec True
h <- fdToHandle w
-- ASSUME we are using utf8 everywhere
hSetEncoding h utf8
hSetBuffering h LineBuffering
return (r, h)
child r = void $ withRunInIO $ \runIO -> do
X.xfork $ runIO $ do
void $ liftIO $ dupTo r stdInput
liftIO $ executeFile "/bin/sh" False ["-c", T.unpack x] Nothing
-- spawnPipeRW
-- :: (MonadReader env m, HasLogFunc env, MonadUnliftIO m)
-- => T.Text
-- -> m Handle
-- spawnPipeRW x = do
-- (r, h) <- liftIO mkPipe
-- child r
-- liftIO $ closeFd r
-- return h
-- where
-- mkPipe = do
-- (r, w) <- createPipe
-- setFdOption w CloseOnExec True
-- h <- fdToHandle w
-- -- ASSUME we are using utf8 everywhere
-- hSetEncoding h utf8
-- hSetBuffering h LineBuffering
-- return (r, h)
-- child r = void $ withRunInIO $ \runIO -> do
-- X.xfork $ runIO $ do
-- void $ liftIO $ dupTo r stdInput
-- liftIO $ executeFile "/bin/sh" False ["-c", T.unpack x] Nothing
-- | Run 'XMonad.Core.spawn' with a command and arguments
spawnCmd :: MonadIO m => FilePath -> [T.Text] -> m ()