From c5560515a0fe587f9138a045c90b9404d7c8cb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rokas=20Gegevi=C4=8Dius?= Date: Tue, 6 Jun 2023 14:35:09 +0300 Subject: [PATCH 1/2] shell command support --- src/Iris/Browse.hs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Iris/Browse.hs b/src/Iris/Browse.hs index 0df0b0d..64b8f26 100644 --- a/src/Iris/Browse.hs +++ b/src/Iris/Browse.hs @@ -15,11 +15,11 @@ module Iris.Browse ( BrowseException (..), ) where -import Control.Exception (Exception, throwIO) -import System.Directory (findExecutable) -import System.Environment (lookupEnv) -import System.Info (os) -import System.Process (callCommand, showCommandForUser) +import Control.Exception (Exception, throwIO) +import System.Directory (findExecutable) +import System.Environment (lookupEnv) +import System.Info (os) +import System.Process (callCommand, showCommandForUser) {- | Exception thrown by 'openInBrowser'. @@ -73,7 +73,7 @@ openInBrowser file = ] case browserExe of Just browser -> runCommand browser [file] - Nothing -> throwIO $ BrowserNotFoundException curOs + Nothing -> throwIO $ BrowserNotFoundException curOs -- | Execute a command with arguments. runCommand :: FilePath -> [String] -> IO () @@ -89,3 +89,23 @@ findFirstExecutable = \case findExecutable exe >>= \case Nothing -> findFirstExecutable exes Just path -> pure $ Just path + +shell :: FilePath -> [String] -> IO () +shell cmd args = do + hPutStrLn stderr $ "⚙ " ++ cmd ++ " " ++ unwords args + callProcess cmd args + +-- | Run the command but don't print it +shellSilent :: FilePath -> [String] -> IO () +shellSilent cmd args = callProcess cmd args + +-- | Run the command, don't print it and return its stdout +shellRetSilent :: FilePath -> [String] -> IO String +shellRetSilent cmd args = readProcess cmd args "" + +-- | Run the command, print it with prompt to stderr and return its stdout +shellRet :: FilePath -> [String] -> IO String +shellRet cmd args = do + hPutStrLn stderr $ "⚙ " ++ cmd ++ " " ++ unwords args + shellRetSilent cmd args + From 69209cf92418597a1f9ac1cf819a72b52c2ee443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rokas=20Gegevi=C4=8Dius?= Date: Tue, 6 Jun 2023 14:45:56 +0300 Subject: [PATCH 2/2] support for shell commands inside iris --- src/Iris/Browse.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Iris/Browse.hs b/src/Iris/Browse.hs index 64b8f26..e443c98 100644 --- a/src/Iris/Browse.hs +++ b/src/Iris/Browse.hs @@ -19,7 +19,9 @@ import Control.Exception (Exception, throwIO) import System.Directory (findExecutable) import System.Environment (lookupEnv) import System.Info (os) -import System.Process (callCommand, showCommandForUser) +import System.IO (hPutStrLn, stderr) +import System.Process (callCommand, callProcess, readProcess, + showCommandForUser) {- | Exception thrown by 'openInBrowser'. @@ -108,4 +110,3 @@ shellRet :: FilePath -> [String] -> IO String shellRet cmd args = do hPutStrLn stderr $ "⚙ " ++ cmd ++ " " ++ unwords args shellRetSilent cmd args -