Foreign Shell Tools (xonsh.foreign_shells
)¶
Tools to help interface with foreign shells, such as Bash.
-
class
xonsh.foreign_shells.
ForeignShellBaseAlias
(shell, filename, sourcer=None, extra_args=())[source]¶ This class is responsible for calling foreign shell functions as if they were aliases. This does not currently support taking stdin.
Parameters: shell : str
Name or path to shell
filename : str
Where the function is defined, path to source.
sourcer : str or None, optional
Command to source foreign files with.
extra_args : tuple of str, optional
Additional command line options to pass into the shell.
-
INPUT
= 'echo ForeignShellBaseAlias {shell} {filename} {args}\n'¶
-
-
class
xonsh.foreign_shells.
ForeignShellExecAlias
(src, shell, filename='<foreign-shell-exec-alias>', sourcer=None, extra_args=())[source]¶ Provides a callable alias for source code in a foreign shell.
Parameters: src : str
Source code in the shell language
shell : str
Name or path to shell
filename : str
Where the function is defined, path to source.
sourcer : str or None, optional
Command to source foreign files with.
extra_args : tuple of str, optional
Additional command line options to pass into the shell.
-
INPUT
= '{src} {args}\n'¶
-
-
class
xonsh.foreign_shells.
ForeignShellFunctionAlias
(funcname, shell, filename, sourcer=None, extra_args=())[source]¶ This class is responsible for calling foreign shell functions as if they were aliases. This does not currently support taking stdin.
Parameters: funcname : str
function name
shell : str
Name or path to shell
filename : str
Where the function is defined, path to source.
sourcer : str or None, optional
Command to source foreign files with.
extra_args : tuple of str, optional
Additional command line options to pass into the shell.
-
INPUT
= '{sourcer} "{filename}"\n{funcname} {args}\n'¶
-
-
xonsh.foreign_shells.
ensure_shell
(shell)[source]¶ Ensures that a mapping follows the shell specification.
-
xonsh.foreign_shells.
load_foreign_aliases
(shells)[source]¶ Loads aliases from foreign shells.
Parameters: shells : sequence of dicts
An iterable of dicts that can be passed into foreign_shell_data() as keyword arguments.
Returns: aliases : dict
A dictionary of the merged aliases.
-
xonsh.foreign_shells.
load_foreign_envs
(shells)[source]¶ Loads environments from foreign shells.
Parameters: shells : sequence of dicts
An iterable of dicts that can be passed into foreign_shell_data() as keyword arguments.
Returns: env : dict
A dictionary of the merged environments.
-
xonsh.foreign_shells.
parse_aliases
(s, shell, sourcer=None, extra_args=())[source]¶ Parses the aliases portion of string into a dict.
-
xonsh.foreign_shells.
parse_funcs
(s, shell, sourcer=None, extra_args=())[source]¶ Parses the funcs portion of a string into a dict of callable foreign function wrappers.
-
xonsh.foreign_shells.
foreign_shell_data
[source]¶ 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
Additional 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.
show : bool, optional
Whether or not to display the script that will be run.
dryrun : bool, optional
Whether or not to actually run and process the command.
Returns: env : dict
Dictionary of shell’s environment. (None if the subproc command fails)
aliases : dict
Dictionary of shell’s aliases, this includes foreign function wrappers.(None if the subproc command fails)