xonsh.prompt.gitstatus

Informative git status prompt formatter.

Each part of the status field is extendable and customizable.

Following fields are available other than gitstatus

  • gitstatus.ahead

  • gitstatus.behind

  • gitstatus.branch

  • gitstatus.changed

  • gitstatus.clean

  • gitstatus.conflicts

  • gitstatus.deleted

  • gitstatus.lines_added

  • gitstatus.lines_removed

  • gitstatus.numstat

  • gitstatus.operations

  • gitstatus.porcelain

  • gitstatus.repo_path

  • gitstatus.short_head

  • gitstatus.staged

  • gitstatus.stash_count

  • gitstatus.tag

  • gitstatus.tag_or_hash

  • gitstatus.untracked

All the fields have prefix and suffix attribute that can be set in the configuration as shown below. Other attributes can also be changed.

See some examples below,

from xonsh.prompt.base import PromptField, PromptFields

# 1. to change the color of the branch name
$PROMPT_FIELDS['gitstatus.branch'].prefix = "{RED}"

# 2. to change the symbol for conflicts from ``{RED}×``
$PROMPT_FIELDS['gitstatus.conflicts'].prefix = "{GREEN}*"

# 3. hide the branch name if it is main or dev
branch_field = $PROMPT_FIELDS['gitstatus.branch']
old_updator = branch_field.updator
def new_updator(fld: PromptField, ctx: PromptFields):
    old_updator(fld, ctx)
    if fld.value in {"main", "dev"}:
        fld.value = ""
branch_field.updator = new_updator
class xonsh.prompt.gitstatus.GitStatus(*fragments: str, **kwargs)[source]

Return str BRANCH|OPERATOR|numbers

Parameters:
kwargs

attributes of the class will be set from this

get_frags(env)[source]
update(ctx)[source]

will be called from PromptFields getter for each new prompt

classmethod wrap(**kwargs) tp.Callable[..., FieldType]

decorator to set the updator

fragments: tuple[str, ...] = ('.branch', '.ahead', '.behind', '.operations', '{RESET}|', '.staged', '.conflicts', '.changed', '.deleted', '.untracked', '.stash_count', '.lines_added', '.lines_removed', '.clean')

name of the fields or the literals to combine. If the framgment name startswith . then they are resolved to include the name of this field.

hidden = ('.lines_added', '.lines_removed')

These fields will not be processed for the result

property name: str

will be set during load.

Notes

fields with names such as gitstatus.branch mean they are defined in a module named gitstatus and are most likely a subfield used by gitstatus

separator = ''

in case this combines values from other prompt fields

updator: tp.Callable[[FieldType, PromptFields], None] | None = None

this is a callable that needs to update the value or any of the attribute of the field

value = ''

This field should hold the bare value of the field without any color/format strings

class xonsh.prompt.gitstatus.GitStatusPromptField(**kwargs)[source]

Only calls the updator if we are inside a git repository

Parameters:
kwargs

attributes of the class will be set from this

update(ctx)[source]

will be called from PromptFields getter for each new prompt

classmethod wrap(**kwargs) tp.Callable[..., FieldType]

decorator to set the updator

property name: str

will be set during load.

Notes

fields with names such as gitstatus.branch mean they are defined in a module named gitstatus and are most likely a subfield used by gitstatus

prefix = ''
suffix = ''
updator: tp.Callable[[FieldType, PromptFields], None] | None = None

this is a callable that needs to update the value or any of the attribute of the field

value = ''

This field should hold the bare value of the field without any color/format strings

xonsh.prompt.gitstatus.get_gitstatus_info(fld: _GSInfo, ctx: PromptFields) None[source]

Get individual fields from $PROMPT_FIELDS[‘gitstatus.porcelain’]

xonsh.prompt.gitstatus.get_operations(gitdir: str)[source]

get the current git operation e.g. MERGE/REBASE…

xonsh.prompt.gitstatus.get_stash_count(gitdir: str)[source]

Get git-stash count

xonsh.prompt.gitstatus.inside_repo(ctx)[source]