runBuiltinOrExe :: String -> [String] -> Shell ShellProcess
runBuiltinOrExe = run' where -- now this is just for layout...
  run' "env#" _ = return $ BuiltinProcess $ do -- debug builtin
                   (e,l,p) <- envVars
                   oPutStrLn $ "environment\n" ++ unlines (map show e)
                   oPutStrLn $ "locals\n" ++ unlines (map show l)
                   oPutStrLn $ "positionals: " ++ show p
                   return ExitSuccess
  run' "." args = run' "source" args
  run' "source" (f:args) | null args = return $ BuiltinProcess $ source f
                         | otherwise = return $ BuiltinProcess $
                                                withPositionals args $ source f
  run' "source" [] = return $ BuiltinProcess $ fail "filename argument required"
  run' "command" args = return $ BuiltinProcess $ commandBuiltin args
  run' "type" args = return $ BuiltinProcess $ typeBuiltin args
  run' command args = do b <- builtin command
                         return $ case b of
                           Just b' -> BuiltinProcess $ withExitHandler $
                                      withErrorsPrefixed command $ do
                                        openHandles
                                        ec <- b' args -- after builtins are run.
                                        oFlush `mplus` return () -- to behave like external
                                        eFlush `mplus` return () -- commands, need to flush
                                        return ec
                           Nothing -> ExternalProcess $ withExitHandler $
                                        runWithArgs command args
runBuiltinOrExe :: String -> [String] -> Shell ShellProcess
runBuiltinOrExe = run' where -- now this is just for layout...
  run' "env#" _ = return $ BuiltinProcess $ do -- debug builtin
                   (e,l,p) <- envVars
                   oPutStrLn $ "environment\n" ++ unlines (map show e)
                   oPutStrLn $ "locals\n" ++ unlines (map show l)
                   oPutStrLn $ "positionals: " ++ show p
                   return ExitSuccess
  run' "." args = run' "source" args
  run' "source" (f:args) | null args = return $ BuiltinProcess $ source f
                         | otherwise = return $ BuiltinProcess $
                                                withPositionals args $ source f
  run' "source" [] = return $ BuiltinProcess $ fail "filename argument required"
  run' "command" args = return $ BuiltinProcess $ commandBuiltin args
  run' "type" args = return $ BuiltinProcess $ typeBuiltin args
  run' command args = do b <- builtin command
                         return $ case b of
                           Just b' -> BuiltinProcess $ withExitHandler $
                                      withErrorsPrefixed command $ do
                                        openHandles
                                        ec <- b' args -- after builtins are run.
                                        oFlush `mplus` return () -- to behave like external
                                        eFlush `mplus` return () -- commands, need to flush
                                        return ec
                           Nothing -> ExternalProcess $ withExitHandler $
                                        runWithArgs command args
runBuiltinOrExe = run' where -- now this is just for layout...
  run' "env#" _ = return $ BuiltinProcess $ do -- debug builtin
                   (e,l,p) <- envVars
                   oPutStrLn $ "environment\n" ++ unlines (map show e)
                   oPutStrLn $ "locals\n" ++ unlines (map show l)
                   oPutStrLn $ "positionals: " ++ show p
                   return ExitSuccess
  run' "." args = run' "source" args
  run' "source" (f:args) | null args = return $ BuiltinProcess $ source f
                         | otherwise = return $ BuiltinProcess $
                                                withPositionals args $ source f
  run' "source" [] = return $ BuiltinProcess $ fail "filename argument required"
  run' "command" args = return $ BuiltinProcess $ commandBuiltin args
  run' "type" args = return $ BuiltinProcess $ typeBuiltin args
  run' command args = do b <- builtin command
                         return $ case b of
                           Just b' -> BuiltinProcess $ withExitHandler $
                                      withErrorsPrefixed command $ do
                                        openHandles
                                        ec <- b' args -- after builtins are run.
                                        oFlush `mplus` return () -- to behave like external
                                        eFlush `mplus` return () -- commands, need to flush
                                        return ec
                           Nothing -> ExternalProcess $ withExitHandler $
                                        runWithArgs command args