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 all commits
Commits
File filter

Filter by extension

Filter by extension

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

29 changes: 29 additions & 0 deletions gitsome/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion xonsh/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"


Expand Down