Environment for the xonsh shell.
Base class that implements utilities for PromptFormatters.
You should read the docs for this class to learn how to write your own Prompt Formatter. However, you most likely want to inherit from DefaultPromptFormatter if you are writing a custom formatter.
Custom Prompt Formatters will need to implement their own __init__() that adds entries to several dicts depending on the needs of the variables they add. The Formatter may also implement methods to implement those variables (although very simple variables can be written with pre-existing functions.)
def __init__(self, *args, **kwargs): super(PromptFormatter, self).__init__(*args, **kwargs) # Add a variable that's just a static string. Useful for constants # that you can't remember: self['bell'] = '' # To add a variable that only needs to be computed once add # the function to be called to self. This can be used for any # variable that won't change while this shell instance is run. It is # especially useful if the variable takes a long time to compute and # is infrequently used by users: self['login_time'] = self.login_time # To add a variable that needs to be computed every time the prompt is # printed simply add a function to self and then add the variable name # to the self._run_every set. self['time24'] = functools.partial(time.strftime, '%H:%M:%S') self._run_every.add('time24') def login_time(self): who_out = subprocess.check_output(['who', '-m']) return ' '.join(who_out.decode().split()[2:4])
This class implements the default prompt format variables.
The following variables are recognized:
Name of current user
Name of host computer
Current working directory
Name of current git branch (preceded by a space), if any
Inserts an ANSI color code
Resets any previously used color codes
Gets the branch for a current working directory. Returns None if the cwd is not a repository. This currently only works for git, bust should be extended in the future.
Formats a xonsh prompt template string.
See the DefaultPromptFormatter documentation for keyword arguments recognized in the template string.[
Returns the filler text for the prompt in multiline scenarios.
Attempts to compute the bash envinronment variables.
Attempts to read in xonshrc file, and return the contents.
Constructs a default xonsh environment.