on master help sign in
Centralise bashEscaping
commit5d3d2916f41c8fd90d4368793c3a00359380d724 authorTom Smalley <tfsmalley@gmail.com> dateWed 6 May 2020, 15:26 (6 years ago) parent88d02d5
3 files changed+8−8
lib/command/src/Obelisk/Command.hs+1−3 lib/command/src/Obelisk/Command/Project.hs+4 lib/command/src/Obelisk/Command/Run.hs+3−5
lib/command/src/Obelisk/Command.hs+1−3
@@ -8,7 +8,6 @@ module Obelisk.Command where
88
99import Control.Monad.IO.Class (MonadIO, liftIO)
1010import Data.Bool (bool)
11−import qualified Data.ByteString.UTF8 as BSU
1211import Data.Foldable (for_)
1312import Data.List (isInfixOf, isPrefixOf)
1413import Data.List.NonEmpty (NonEmpty, nonEmpty)
@@ -23,7 +22,6 @@ import System.Environment
2322import System.FilePath
2423import qualified System.Info
2524import System.IO (hIsTerminalDevice, stdout)
26−import Text.ShellEscape (bash, bytes)
2725import System.Posix.Process (executeFile)
2826
2927import Obelisk.App
@@ -400,7 +398,7 @@ ob = \case
400398 ObCommand_Repl interpretPathsList -> withInterpretPaths interpretPathsList runRepl
401399 ObCommand_Watch interpretPathsList -> withInterpretPaths interpretPathsList runWatch
402400 ObCommand_Shell (ShellOpts shellAttr interpretPathsList cmd) -> withInterpretPaths interpretPathsList $ \root interpretPaths ->
403− nixShellForInterpretPaths False shellAttr root interpretPaths (BSU.toString . bytes . bash . BSU.fromString <$> cmd)
401+ nixShellForInterpretPaths False shellAttr root interpretPaths (bashEscape <$> cmd)
404402 ObCommand_Doc shellAttr pkgs -> withInterpretPaths [] $ \root interpretPaths ->
405403 nixShellForInterpretPaths True shellAttr root interpretPaths $ Just $ haddockCommand pkgs
406404 ObCommand_Hoogle shell' port -> withProjectRoot "." $ \root -> do
lib/command/src/Obelisk/Command/Project.hs+4
@@ -15,6 +15,7 @@ module Obelisk.Command.Project
1515 , toImplDir
1616 , toObeliskDir
1717 , withProjectRoot
18+ , bashEscape
1819 ) where
1920
2021import Control.Concurrent.MVar (MVar, newMVar, withMVarMasked)
@@ -286,6 +287,9 @@ nixShellRunConfig root isPure command = do
286287 , [cs]
287288 ])
288289
290+bashEscape :: String -> String
291+bashEscape = BSU.toString . bytes . bash . BSU.fromString
292+
289293nixShellRunProc :: NixShellConfig -> ProcessSpec
290294nixShellRunProc cfg = setDelegateCtlc True $ proc "nix-shell" $ runNixShellConfig cfg
291295
lib/command/src/Obelisk/Command/Run.hs+3−5
@@ -20,7 +20,6 @@ import Control.Monad.IO.Class (liftIO)
2020import Control.Monad.Reader (MonadIO)
2121import Data.Bifoldable (bifoldr1)
2222import Data.Bifunctor (bimap)
23−import qualified Data.ByteString.UTF8 as BSU
2423import Data.Coerce (coerce)
2524import Data.Default (def)
2625import Data.Either (partitionEithers)
@@ -61,7 +60,6 @@ import System.Environment (getExecutablePath)
6160import System.FilePath
6261import qualified System.Info
6362import System.IO.Temp (withSystemTempDirectory)
64−import Text.ShellEscape (bash, bytes)
6563
6664import Obelisk.App (MonadObelisk)
6765import Obelisk.CliApp (
@@ -78,7 +76,7 @@ import Obelisk.CliApp (
7876 withSpinner,
7977 )
8078import Obelisk.Command.Nix
81−import Obelisk.Command.Project (nixShellWithoutPkgs, withProjectRoot, findProjectAssets)
79+import Obelisk.Command.Project (nixShellWithoutPkgs, withProjectRoot, findProjectAssets, bashEscape)
8280import Obelisk.Command.Thunk (attrCacheFileName)
8381import Obelisk.Command.Utils (findExePath, ghcidExePath)
8482
@@ -466,7 +464,7 @@ runGhciRepl root (toList -> packages) ghciArgs =
466464 -- NOTE: We do *not* want to use $(staticWhich "ghci") here because we need the
467465 -- ghc that is provided by the shell in the user's project.
468466 nixShellWithoutPkgs root True False (packageInfoToNamePathMap packages) "ghc" $
469− Just $ unwords $ fmap (BSU.toString . bytes . bash . BSU.fromString) $ "ghci" : ghciArgs
467+ Just $ unwords $ fmap bashEscape $ "ghci" : ghciArgs
470468
471469-- | Run ghcid
472470runGhcid
@@ -479,7 +477,7 @@ runGhcid
479477 -> m ()
480478runGhcid root chdirToRoot ghciArgs (toList -> packages) mcmd =
481479 nixShellWithoutPkgs root True chdirToRoot (packageInfoToNamePathMap packages) "ghc" $
482− Just $ unwords $ fmap (BSU.toString . bytes . bash . BSU.fromString) $ ghcidExePath : opts
480+ Just $ unwords $ fmap bashEscape $ ghcidExePath : opts
483481 where
484482 opts = concat
485483 [ ["-W"]