def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,<EOL>aliascmd=None, extra_args=(), currenv=None,<EOL>safe=False, prevcmd='<STR_LIT>', postcmd='<STR_LIT>', funcscmd=None,<EOL>sourcer=None, use_tmpfile=False, tmpfile_ext=None,<EOL>runcmd=None, seterrprevcmd=None, seterrpostcmd=None):
cmd = [shell]<EOL>cmd.extend(extra_args)  <EOL>if interactive:<EOL><INDENT>cmd.append('<STR_LIT>')<EOL><DEDENT>if login:<EOL><INDENT>cmd.append('<STR_LIT>')<EOL><DEDENT>shkey = CANON_SHELL_NAMES[shell]<EOL>envcmd = DEFAULT_ENVCMDS.get(shkey, '<STR_LIT>') if envcmd is None else envcmd<EOL>tmpfile_ext = DEFAULT_TMPFILE_EXT.get(shkey, '<STR_LIT>') if tmpfile_ext is None else tmpfile_ext<EOL>runcmd = DEFAULT_RUNCMD.get(shkey, '<STR_LIT:-c>') if runcmd is None else runcmd<EOL>seterrprevcmd = DEFAULT_SETERRPREVCMD.get(shkey, '<STR_LIT>')if seterrprevcmd is None else seterrprevcmd<EOL>seterrpostcmd = DEFAULT_SETERRPOSTCMD.get(shkey, '<STR_LIT>')if seterrpostcmd is None else seterrpostcmd<EOL>command = COMMAND.format(envcmd=envcmd, prevcmd=prevcmd,<EOL>postcmd=postcmd,<EOL>seterrprevcmd=seterrprevcmd,<EOL>seterrpostcmd=seterrpostcmd).strip()<EOL>cmd.append(runcmd)<EOL>if not use_tmpfile:<EOL><INDENT>cmd.append(command)<EOL><DEDENT>else:<EOL><INDENT>tmpfile = NamedTemporaryFile(suffix=tmpfile_ext, delete=False)<EOL>tmpfile.write(command.encode('<STR_LIT:utf8>'))<EOL>tmpfile.close()<EOL>cmd.append(tmpfile.name)<EOL><DEDENT>if currenv is not None:<EOL><INDENT>currenv = os.environ<EOL><DEDENT>try:<EOL><INDENT>s = subprocess.check_output(cmd, stderr=subprocess.PIPE, env=currenv,<EOL>start_new_session=True,<EOL>universal_newlines=True)<EOL><DEDENT>except (subprocess.CalledProcessError, FileNotFoundError):<EOL><INDENT>if not safe:<EOL><INDENT>raise<EOL><DEDENT>return None, None<EOL><DEDENT>finally:<EOL><INDENT>if use_tmpfile:<EOL><INDENT>pass<EOL>os.remove(tmpfile.name)<EOL><DEDENT><DEDENT>env = parse_env(s)<EOL>return env<EOL>
Extracts data from a foreign (non-xonsh) shells. Currently this gets
    the environment, aliases, and functions but may be extended in the future.

    Parameters
    ----------
    shell : str
        The name of the shell, such as 'bash' or '/bin/sh'.
    interactive : bool, optional
        Whether the shell should be run in interactive mode.
    login : bool, optional
        Whether the shell should be a login shell.
    envcmd : str or None, optional
        The command to generate environment output with.
    aliascmd : str or None, optional
        The command to generate alias output with.
    extra_args : tuple of str, optional
        Addtional command line options to pass into the shell.
    currenv : tuple of items or None, optional
        Manual override for the current environment.
    safe : bool, optional
        Flag for whether or not to safely handle exceptions and other errors.
    prevcmd : str, optional
        A command to run in the shell before anything else, useful for
        sourcing and other commands that may require environment recovery.
    postcmd : str, optional
        A command to run after everything else, useful for cleaning up any
        damage that the prevcmd may have caused.
    funcscmd : str or None, optional
        This is a command or script that can be used to determine the names
        and locations of any functions that are native to the foreign shell.
        This command should print *only* a JSON object that maps
        function names to the filenames where the functions are defined.
        If this is None, then a default script will attempted to be looked
        up based on the shell name. Callable wrappers for these functions
        will be returned in the aliases dictionary.
    sourcer : str or None, optional
        How to source a foreign shell file for purposes of calling functions
        in that shell. If this is None, a default value will attempt to be
        looked up based on the shell name.
    use_tmpfile : bool, optional
        This specifies if the commands are written to a tmp file or just
        parsed directly to the shell
    tmpfile_ext : str or None, optional
        If tmpfile is True this sets specifies the extension used.
    runcmd : str or None, optional
        Command line switches to use when running the script, such as
        -c for Bash and /C for cmd.exe.
    seterrprevcmd : str or None, optional
        Command that enables exit-on-error for the shell that is run at the
        start of the script. For example, this is "set -e" in Bash. To disable
        exit-on-error behavior, simply pass in an empty string.
    seterrpostcmd : str or None, optional
        Command that enables exit-on-error for the shell that is run at the end
        of the script. For example, this is "if errorlevel 1 exit 1" in
        cmd.exe. To disable exit-on-error behavior, simply pass in an
        empty string.

    Returns
    -------
    env : dict
        Dictionary of shell's environment
    aliases : dict
        Dictionary of shell's alaiases, this includes foreign function
        wrappers.