Last active
December 29, 2015 14:42
-
-
Save acdimalev/d57a56309cbedf56d34d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
import System.Directory as D | |
import System.Posix.Signals as S | |
import System.Posix.Process as P | |
import System.Posix.Terminal as T | |
hiddenFile = (== '.') . head | |
signals = [S.sigTTOU] | |
ignoreSignal signal = installHandler signal S.Ignore Nothing | |
defaultSignal signal = installHandler signal S.Default Nothing | |
ignoreSignals = sequence $ fmap ignoreSignal signals | |
defaultSignals = sequence $ fmap defaultSignal signals | |
foregroundProcessGroup = T.setTerminalProcessGroupID 0 | |
foregroundMyself = getProcessGroupID >>= foregroundProcessGroup | |
waitForProcess = getProcessStatus True True | |
exec cmd = do | |
let bin = head cmd | |
args = tail cmd | |
P.getProcessID >>= P.createProcessGroupFor >>= foregroundProcessGroup | |
defaultSignals | |
executeFile bin True args Nothing | |
setup = ignoreSignals | |
lsPath' = fmap sort . D.getDirectoryContents | |
lsPath = fmap (filter $ not.hiddenFile) . lsPath' | |
ls' = lsPath' "." | |
ls = lsPath "." | |
cd = D.setCurrentDirectory | |
run cmd = do | |
pid <- forkProcess $ exec cmd | |
pgid <- P.createProcessGroupFor pid | |
foregroundProcessGroup pgid | |
status <- waitForProcess pid | |
foregroundMyself | |
return (pid, status) | |
fg pid = do | |
pgid <- P.getProcessGroupIDOf pid | |
foregroundProcessGroup pgid | |
S.signalProcessGroup S.sigCONT pgid | |
status <- waitForProcess pid | |
foregroundMyself | |
return (pid, status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment