更改用于在GHCi中运行“shell命令”的shell

时间:2017-09-08 12:15:39

标签: haskell ghci

在GHCi中,可以使用:!<command>执行shell命令。默认情况下,似乎使用了sh shell:

Prelude> :!echo $0
/bin/sh

我为我在系统(fish)上使用的shell定义了许多别名和自定义函数,我想从GHCi中使用它们,但不必将它们转换为{{1兼容版本。

有没有办法更改GHCi用于执行sh命令的shell?我无法为此找到任何:!选项,也没有为GHCi找到任何命令行参数。

1 个答案:

答案 0 :(得分:4)

:! command in current versions of ghci是对System.Process.system

的调用
-- | Entry point for execution a ':<command>' input from user
specialCommand :: String -> InputT GHCi Bool
specialCommand ('!':str) = lift $ shellEscape (dropWhile isSpace str)
-- [...]

shellEscape :: String -> GHCi Bool
shellEscape str = liftIO (system str >> return False)

我怀疑system已被硬编码到/bin/sh,但您无法define your own ghci command进行fish次呼叫。我没有安装fish,因此我将使用bash作为示例:

λ import System.Process (rawSystem)
λ :def bash \cmd -> rawSystem "/bin/bash" ["-c", cmd] >> return ""
λ :bash echo $0
/bin/bash
相关问题