summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorFraser Tweedale <frase@frase.id.au>2019-04-10 22:00:18 +1000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-04-15 06:26:38 -0400
commitaa490b350b35a07495837e96d01137ed50915131 (patch)
tree9ff5c0446d4cdbbcacd6a9e58080fef702588790 /ghc
parent5c06b60d0e2e270c9ccacebb96ca0da4d0f4e6d9 (diff)
downloadhaskell-aa490b350b35a07495837e96d01137ed50915131.tar.gz
GHCi: add 'local-config' setting
Add the ':set local-config { source | ignore }' setting to control whether .ghci file in current directory will be sourced or not. The directive can be set in global config or $HOME/.ghci, which are processed before local .ghci files. The default is "source", preserving current behaviour. Related: https://gitlab.haskell.org/ghc/ghc/issues/6017 Related: https://gitlab.haskell.org/ghc/ghc/issues/14250
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 55d06dcc1e..21ef7969ba 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -351,13 +351,16 @@ defFullHelpText =
"\n" ++
" :set <option> ... set options\n" ++
" :seti <option> ... set options for interactive evaluation only\n" ++
+ " :set local-config { source | ignore }\n" ++
+ " set whether to source .ghci in current dir\n" ++
+ " (loading untrusted config is a security issue)\n" ++
" :set args <arg> ... set the arguments returned by System.getArgs\n" ++
" :set prog <progname> set the value returned by System.getProgName\n" ++
" :set prompt <prompt> set the prompt used in GHCi\n" ++
" :set prompt-cont <prompt> set the continuation prompt used in GHCi\n" ++
" :set prompt-function <expr> set the function to handle the prompt\n" ++
- " :set prompt-cont-function <expr>" ++
- "set the function to handle the continuation prompt\n" ++
+ " :set prompt-cont-function <expr>\n" ++
+ " set the function to handle the continuation prompt\n" ++
" :set editor <cmd> set the command used for :edit\n" ++
" :set stop [<n>] <cmd> set the command to run when a breakpoint is hit\n" ++
" :unset <option> ... unset options\n" ++
@@ -2689,6 +2692,8 @@ setCmd str
Right ("editor", rest) -> setEditor $ dropWhile isSpace rest
Right ("stop", rest) -> setStop $ dropWhile isSpace rest
+ Right ("local-config", rest) ->
+ setLocalConfigBehaviour $ dropWhile isSpace rest
_ -> case toArgs str of
Left err -> liftIO (hPutStrLn stderr err)
Right wds -> setOptions wds
@@ -2754,6 +2759,7 @@ showDynFlags show_all dflags = do
setArgs, setOptions :: GhciMonad m => [String] -> m ()
setProg, setEditor, setStop :: GhciMonad m => String -> m ()
+setLocalConfigBehaviour :: GhciMonad m => String -> m ()
setArgs args = do
st <- getGHCiState
@@ -2767,6 +2773,14 @@ setProg prog = do
setEditor cmd = modifyGHCiState (\st -> st { editor = cmd })
+setLocalConfigBehaviour s
+ | s == "source" =
+ modifyGHCiState (\st -> st { localConfig = SourceLocalConfig })
+ | s == "ignore" =
+ modifyGHCiState (\st -> st { localConfig = IgnoreLocalConfig })
+ | otherwise = throwGhcException
+ (CmdLineError "syntax: :set local-config { source | ignore }")
+
setStop str@(c:_) | isDigit c
= do let (nm_str,rest) = break (not.isDigit) str
nm = read nm_str