diff --git a/docs/api/index.rst b/docs/api/index.rst index 8d72e5bff..df2bedda4 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -32,6 +32,7 @@ For those of you who want the gritty details. history completer completers/index + prompt/index shell base_shell readline_shell diff --git a/docs/api/prompt/gitstatus.rst b/docs/api/prompt/gitstatus.rst new file mode 100644 index 000000000..365db8890 --- /dev/null +++ b/docs/api/prompt/gitstatus.rst @@ -0,0 +1,11 @@ +.. _xonsh_prompt_gitstatus: + +*********************************************** +Git status prompt (``xonsh.prompt.gitstatus``) +*********************************************** + +.. automodule:: xonsh.prompt.gitstatus + :members: + :undoc-members: + :inherited-members: + diff --git a/docs/api/prompt/index.rst b/docs/api/prompt/index.rst new file mode 100644 index 000000000..67b3bfb92 --- /dev/null +++ b/docs/api/prompt/index.rst @@ -0,0 +1,12 @@ +.. _api_prompt: + +================= +Prompt API +================= +Functions in ``FORMATTER_DICT`` for prompt. + +.. toctree:: + :maxdepth: 1 + + gitstatus + vc_branch diff --git a/docs/api/prompt/vc_branch.rst b/docs/api/prompt/vc_branch.rst new file mode 100644 index 000000000..596dd2887 --- /dev/null +++ b/docs/api/prompt/vc_branch.rst @@ -0,0 +1,11 @@ +.. _xonsh_prompt_vc_branch: + +******************************************************************* +Version control branch info prompt (``xonsh.prompt.vc_branch``) +******************************************************************* + +.. automodule:: xonsh.prompt.vc_branch + :members: + :undoc-members: + :inherited-members: + diff --git a/xonsh/prompt/base.py b/xonsh/prompt/base.py index 0792ac22b..aa1a2c7a2 100644 --- a/xonsh/prompt/base.py +++ b/xonsh/prompt/base.py @@ -16,7 +16,7 @@ from xonsh.prompt.env import (env_name, vte_new_tab_cwd) from xonsh.prompt.vc_branch import ( current_branch, branch_color, branch_bg_color ) -from xonsh.prompt.gitstatus import _gitstatus_prompt +from xonsh.prompt.gitstatus import gitstatus_prompt FORMATTER_DICT = xl.LazyObject(lambda: dict( @@ -33,5 +33,5 @@ FORMATTER_DICT = xl.LazyObject(lambda: dict( current_job=_current_job, env_name=env_name, vte_new_tab_cwd=vte_new_tab_cwd, - gitstatus=_gitstatus_prompt, + gitstatus=gitstatus_prompt, ), globals(), 'FORMATTER_DICT') diff --git a/xonsh/prompt/gitstatus.py b/xonsh/prompt/gitstatus.py index 2dbe62176..2fa1e5493 100644 --- a/xonsh/prompt/gitstatus.py +++ b/xonsh/prompt/gitstatus.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - """informative git status for prompt""" import os @@ -19,8 +18,8 @@ def _check_output(*args, **kwargs): @xl.lazyobject -def DEFS(): - _DEFS = { +def _DEFS(): + DEFS = { 'HASH': ':', 'BRANCH': '{CYAN}', 'OPERATION': '{CYAN}', @@ -33,11 +32,11 @@ def DEFS(): 'AHEAD': '↑·', 'BEHIND': '↓·', } - return _DEFS + return DEFS def _get_def(key): - return builtins.__xonsh_env__.get('XONSH_GITSTATUS_' + key) or DEFS[key] + return builtins.__xonsh_env__.get('XONSH_GITSTATUS_' + key) or _DEFS[key] def _get_tag_or_hash(): @@ -69,7 +68,10 @@ def _gitoperation(gitdir): if os.path.exists(os.path.join(gitdir, f[0]))] -def _gitstatus(): +def gitstatus(): + """Return (branch name, number of ahead commit, number of behind commit, + untracked number, changed number, conflicts number, + staged number, stashed number, operation)""" status = _check_output(['git', 'status', '--porcelain', '--branch']) branch = '' num_ahead, num_behind = 0, 0 @@ -113,11 +115,12 @@ def _gitstatus(): operations) -def _gitstatus_prompt(): +def gitstatus_prompt(): + """Return str `[BRANCH|OPERATOR|numbers]`""" try: (branch, num_ahead, num_behind, untracked, changed, conflicts, staged, stashed, - operations) = _gitstatus() + operations) = gitstatus() except subprocess.SubprocessError: return '' diff --git a/xonsh/tracer.py b/xonsh/tracer.py index 784982845..4c48aac02 100644 --- a/xonsh/tracer.py +++ b/xonsh/tracer.py @@ -12,7 +12,7 @@ from xonsh.lazyasd import LazyObject from xonsh.platform import HAS_PYGMENTS from xonsh.tools import DefaultNotGiven, print_color, normabspath, to_bool from xonsh.inspectors import find_file, getouterframes -from xonsh.environ import _replace_home +from xonsh.prompt.cwd import _replace_home from xonsh.lazyimps import pygments, pyghooks