https://github.com/spitfire1900/xontrib-pygitstatus
PyGit2 implementation of the gitstatus prompt for Xonsh shell
https://github.com/spitfire1900/xontrib-pygitstatus
git gitstatus pygit2 xonsh xonsh-prompt xontrib
Last synced: about 2 months ago
JSON representation
PyGit2 implementation of the gitstatus prompt for Xonsh shell
- Host: GitHub
- URL: https://github.com/spitfire1900/xontrib-pygitstatus
- Owner: Spitfire1900
- License: lgpl-3.0
- Created: 2024-03-22T03:05:29.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-03T19:17:11.000Z (4 months ago)
- Last Synced: 2025-02-08T06:19:27.155Z (2 months ago)
- Topics: git, gitstatus, pygit2, xonsh, xonsh-prompt, xontrib
- Language: Python
- Homepage:
- Size: 136 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PyGit2 implementation of the builtin gitstatus PROMPT fields.xontrib-pygitstatus provides a set of PROMPT fields that mimic the behavior of the builtin gitstatus prompt fields with [minor differences](#differences-from-gitstatus).
Unlike the builtin prompt, xontrib-pygitstatus does not invoke the git cli, so may be more performant in the following cases:
- You're on a Windows workstations, where process spawning is slower than Linux
- You have an on-access virtus scanner installed, which will slow down git cli invocations
- Git is not installed on your system## Installation
To install use pip:
```xsh
xpip install xontrib-pygitstatus
# or: xpip install -U git+https://github.com//xontrib-pygitstatus
```## Usage
This xontrib will get loaded automatically for interactive sessions.
To stop this, set```xsh
$XONTRIBS_AUTOLOAD_DISABLED = ["pygitstatus", ]
# if you have set this for other xontribs, you should append the vale
```then use pygitstatus's prompts in your .xonshrc file:
```xsh
PROMPT = '{pygitstatus}'
```Example modified default prompt:
```xsh
$PROMPT = '{YELLOW}{env_name}{RESET}{BOLD_GREEN}{user}@{hostname}{BOLD_BLUE} {cwd}{pygitstatus.branch_color}{pygitstatus_curr_branch: {}}{RESET} {RED}{last_return_code_if_nonzero:[{BOLD_INTENSE_RED}{}{RED}] }{RESET}{BOLD_BLUE}{prompt_end}{RESET}'
```## Differences from gitstatus
PyGitStatus is a reimplementation of the [gitstatus](https://github.com/xonsh/xonsh/blob/0.12.5/xonsh/prompt/gitstatus.py) that nearly follows the same logic as the original gitstatus prompt, but with a few differences:
- Conflict files are intentionally excluded from pygitstatus.staged.
- Merge conflicts on files that are both added to the index and the working tree are counted as conflicts.
- Untracked files is calculated recursively, this has the same macro-performance as only counting untracked files and directories in the current directory.gitstatus uses `git status --porcelain`, which is unable to distinguish between a conflict file and one that was added to both the index and working tree.
## Fields
```xsh
{pygitstatus}
{pygitstatus_curr_branch}
{pygitstatus.ahead}
{pygitstatus.behind}
{pygitstatus.branch}
{pygitstatus.branch_bg_color}
{pygitstatus.branch_color}
{pygitstatus.changed}
{pygitstatus.clean}
{pygitstatus.conflicts}
{pygitstatus.deleted}
{pygitstatus.lines_added}
{pygitstatus.lines_deleted}
{pygitstatus.numstat}
{pygitstatus.operations}
{pygitstatus.repo_path}
{pygitstatus.short_head}
{pygitstatus.staged}
{pygitstatus.stash_count}
{pygitstatus.tag}
{pygitstatus.tag_or_hash}
{pygitstatus.untracked}
```## Known issues
While this xontrib works on Windows, the tests do not pass on Windows.
## Credits
This package was created with [xontrib template](https://github.com/xonsh/xontrib-template).