Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable prompt #131

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitsomeconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,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}

29 changes: 29 additions & 0 deletions gitsome/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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'
Expand All @@ -144,8 +145,10 @@ def __init__(self):
self.verify_ssl = True
self.urls = []
self._init_colors()
self._init_prompt()
self.load_configs([
self.load_config_colors,
self.load_prompt,
])
self.login = login
self.authorize = authorize
Expand Down Expand Up @@ -174,6 +177,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.
Expand Down Expand Up @@ -549,6 +564,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.

Expand Down Expand Up @@ -703,6 +729,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)

Expand Down
12 changes: 3 additions & 9 deletions xonsh/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from functools import wraps
from collections import MutableMapping, MutableSequence, MutableSet, namedtuple

from gitsome.config import Config
from xonsh import __version__ as XONSH_VERSION
from xonsh.tools import TERM_COLORS, ON_WINDOWS, ON_MAC, ON_LINUX, ON_ARCH, \
is_int, always_true, always_false, ensure_string, is_env_path, str_to_env_path, \
Expand Down Expand Up @@ -79,15 +80,8 @@ def is_callable_default(x):
"""Checks if a value is a callable default."""
return callable(x) and getattr(x, '_xonsh_callable_default', False)

DEFAULT_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} ')
config = Config()
DEFAULT_PROMPT = config.prompt
DEFAULT_TITLE = '{user} at {hostname}: {cwd} | xonsh'

@default_value
Expand Down