diff --git a/.gitsomeconfig b/.gitsomeconfig index 36b0498..3c808eb 100644 --- a/.gitsomeconfig +++ b/.gitsomeconfig @@ -22,4 +22,6 @@ clr_tooltip = None clr_user = cyan clr_view_link = magenta clr_view_index = magenta +prompt = {BOLD_RED}{user} {BOLD_WHITE}at {BOLD_RED}{hostname} {BOLD_WHITE}in {BOLD_GREEN}{cwd} {BOLD_WHITE}on{branch_color}{curr_branch} {BOLD_WHITE} + ${NO_COLOR} diff --git a/gitsome/config.py b/gitsome/config.py index b2e5cbd..a112450 100644 --- a/gitsome/config.py +++ b/gitsome/config.py @@ -126,6 +126,7 @@ class Config(object): CONFIG_CLR_VIEW_LINK = 'clr_view_link' CONFIG_CLR_VIEW_INDEX = 'clr_view_index' CONFIG_SECTION = 'github' + CONFIG_PROMPT = 'prompt' CONFIG_USER_LOGIN = 'user_login' CONFIG_USER_PASS = 'user_pass' CONFIG_USER_TOKEN = 'user_token' @@ -149,8 +150,10 @@ def __init__(self): self.urls = [] self.enable_avatar = True self._init_colors() + self._init_prompt() self.load_configs([ self.load_config_colors, + self.load_prompt, ]) self.login = login self.authorize = authorize @@ -179,6 +182,18 @@ def _init_colors(self): self.clr_view_link = 'magenta' self.clr_view_index = 'magenta' + def _init_prompt(self): + """Initialize prompt to its default.""" + self.prompt = ('{BOLD_RED}{user} ' + '{BOLD_WHITE}at ' + '{BOLD_RED}{hostname} ' + '{BOLD_WHITE}in ' + '{BOLD_GREEN}{cwd} ' + '{BOLD_WHITE}on' + '{branch_color}{curr_branch} ' + '{BOLD_WHITE}\n' + '${NO_COLOR} ') + def authenticate_cached_credentials(self, config, parser, enterprise_auth=enterprise_login): """Authenticate with the user's credentials in ~/.gitsomeconfig. @@ -558,6 +573,17 @@ def load_colors(self, parser): default=self.clr_view_index, color_config=True) + def load_prompt(self, parser): + """Load prompt from ~/.gitsomeconfig. + + :type parser: :class:`ConfigParser.RawConfigParser` + :param parser: An instance of `ConfigParser.RawConfigParser`. + """ + self.prompt = self.load_config( + parser=parser, + cfg_label=self.CONFIG_PROMPT, + default=self.prompt) + def load_urls(self, view_in_browser): """Load the current set of urls from ~/.gitsomeconfigurl. @@ -716,6 +742,9 @@ def save_config(self): parser.set(self.CONFIG_SECTION, self.CONFIG_CLR_VIEW_INDEX, self.clr_view_index) + parser.set(self.CONFIG_SECTION, + self.CONFIG_PROMPT, + self.prompt) with open(config, 'w+') as config_file: parser.write(config_file) diff --git a/xonsh/environ.py b/xonsh/environ.py index 0913c70..cdf0bee 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -13,6 +13,7 @@ import collections.abc as cabc import subprocess +from gitsome.config import Config from xonsh import __version__ as XONSH_VERSION from xonsh.lazyasd import LazyObject, lazyobject from xonsh.codecache import run_script_with_cache @@ -603,9 +604,11 @@ def default_value(f): def is_callable_default(x): """Checks if a value is a callable default.""" - return callable(x) and getattr(x, "_xonsh_callable_default", False) + return callable(x) and getattr(x, '_xonsh_callable_default', False) +config = Config() +DEFAULT_PROMPT = config.prompt DEFAULT_TITLE = "{current_job:{} | }{user}@{hostname}: {cwd} | xonsh"