mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
api docs for prompt
This commit is contained in:
parent
f8c345bd70
commit
e1008e8202
7 changed files with 49 additions and 11 deletions
|
@ -32,6 +32,7 @@ For those of you who want the gritty details.
|
|||
history
|
||||
completer
|
||||
completers/index
|
||||
prompt/index
|
||||
shell
|
||||
base_shell
|
||||
readline_shell
|
||||
|
|
11
docs/api/prompt/gitstatus.rst
Normal file
11
docs/api/prompt/gitstatus.rst
Normal file
|
@ -0,0 +1,11 @@
|
|||
.. _xonsh_prompt_gitstatus:
|
||||
|
||||
***********************************************
|
||||
Git status prompt (``xonsh.prompt.gitstatus``)
|
||||
***********************************************
|
||||
|
||||
.. automodule:: xonsh.prompt.gitstatus
|
||||
:members:
|
||||
:undoc-members:
|
||||
:inherited-members:
|
||||
|
12
docs/api/prompt/index.rst
Normal file
12
docs/api/prompt/index.rst
Normal file
|
@ -0,0 +1,12 @@
|
|||
.. _api_prompt:
|
||||
|
||||
=================
|
||||
Prompt API
|
||||
=================
|
||||
Functions in ``FORMATTER_DICT`` for prompt.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
|
||||
gitstatus
|
||||
vc_branch
|
11
docs/api/prompt/vc_branch.rst
Normal file
11
docs/api/prompt/vc_branch.rst
Normal file
|
@ -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:
|
||||
|
|
@ -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')
|
||||
|
|
|
@ -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 ''
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue