diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-12-25 12:28:47 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-12-25 13:48:00 +0530 |
| commit | b4fe44842fb6914f9060b0d018de53983b0aab0b (patch) | |
| tree | ee0d740e4500153c859d5fa02d4f6f8fa95404e6 /lib/Daffm/Action/Commands.hs | |
| parent | 2a2ee4a51e160406522c8c3136dfbc030ad3dcdd (diff) | |
| download | daffm-b4fe44842fb6914f9060b0d018de53983b0aab0b.tar.gz daffm-b4fe44842fb6914f9060b0d018de53983b0aab0b.zip | |
Add env vars for managing escape-free commands
Diffstat (limited to '')
| -rw-r--r-- | lib/Daffm/Action/Commands.hs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Daffm/Action/Commands.hs b/lib/Daffm/Action/Commands.hs index 9a90f93..39534e1 100644 --- a/lib/Daffm/Action/Commands.hs +++ b/lib/Daffm/Action/Commands.hs @@ -21,6 +21,7 @@ import qualified Data.Text as Text import qualified Data.Text.IO as Text import qualified System.Process as Proc import Text.Read (readMaybe) +import System.Environment (getEnvironment) runCmdline :: AppEvent () runCmdline = do @@ -67,14 +68,16 @@ parseCommand cmd = mkCmd . splitCmdArgs $ trimStart cmd ("", _) -> Nothing (cmd', args) -> Just $ CmdCustom cmd' args -readCommandLines :: Text.Text -> IO [Text.Text] -readCommandLines cmd = do +readCommandLines :: Map.Map String String -> Text.Text -> IO [Text.Text] +readCommandLines env cmd = do + cmdEnv <- (++ Map.toList env) <$> getEnvironment Proc.withCreateProcess (Proc.shell $ Text.unpack cmd) { Proc.delegate_ctlc = True, Proc.std_in = Proc.NoStream, Proc.std_out = Proc.CreatePipe, - Proc.std_err = Proc.NoStream + Proc.std_err = Proc.NoStream, + Proc.env = Just cmdEnv } $ \_ stdout _ p -> do _ <- Proc.waitForProcess p @@ -88,7 +91,8 @@ processCommand (CmdShell waitForKey cmd) args = do cmdSubstitutions (argSubst args cmd) >>= suspendAndRunShellCommand waitForKey reloadDir processCommand (CmdCommandShell cmd) args = do - stdout <- cmdSubstitutions (argSubst args cmd) >>= liftIO . readCommandLines + env <- gets geCommandEnvFromState + stdout <- cmdSubstitutions (argSubst args cmd) >>= liftIO . readCommandLines env forM_ stdout runIfCmd reloadDir where |
