In GHCi, a shell command can be executed using :!<command>. By default, it seems that the sh shell is used:
Prelude> :!echo $0
/bin/sh
I have a number of aliases and custom functions defined for the shell I use generally on my system (fish), and I'd like to use these from GHCi but not have to translate them into sh-compatible versions.
Is there a way of changing the shell GHCi uses to execute :! commands? I haven't been able to find any :set options for this, nor any command-line arguments to GHCi to do this.
The :! command in current versions of ghci is a call to 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)
I suspect system is hardcoded to /bin/sh, but there's no reason you can't define your own ghci command to do fish calls. I don't have fish installed, so I'll use bash as an example:
λ import System.Process (rawSystem)
λ :def bash \cmd -> rawSystem "/bin/bash" ["-c", cmd] >> return ""
λ :bash echo $0
/bin/bash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With