diff --git a/TODO.md b/TODO.md index c371313..69a8f62 100644 --- a/TODO.md +++ b/TODO.md @@ -9,7 +9,7 @@ 'gitstatus.branch': , # DONE 'gitstatus.ahead': , # DONE 'gitstatus.behind': , # DONE -'gitstatus.untracked': , # TODO +'gitstatus.untracked': , # DONE 'gitstatus.changed': , # TODO 'gitstatus.deleted': , # TODO 'gitstatus.conflicts': , # TODO diff --git a/xontrib/pygitstatus/entrypoint.py b/xontrib/pygitstatus/entrypoint.py index 28f209a..084222b 100644 --- a/xontrib/pygitstatus/entrypoint.py +++ b/xontrib/pygitstatus/entrypoint.py @@ -2,7 +2,7 @@ from xonsh.built_ins import XonshSession -from .prompt import ahead, behind, branch, clean, repo_path, short_head, tag +from .prompt import (ahead, behind, branch, clean, repo_path, short_head, tag, untracked) def _load_xontrib_(xsh: XonshSession, **_): @@ -24,6 +24,7 @@ def _load_xontrib_(xsh: XonshSession, **_): prompt_fields['pygitstatus.repo_path'] = repo_path prompt_fields['pygitstatus.short_head'] = short_head prompt_fields['pygitstatus.tag'] = tag + prompt_fields['pygitstatus.untracked'] = untracked def _unload_xontrib_(xsh: XonshSession, **kwargs) -> dict: diff --git a/xontrib/pygitstatus/prompt.py b/xontrib/pygitstatus/prompt.py index e192c1c..6b93d47 100644 --- a/xontrib/pygitstatus/prompt.py +++ b/xontrib/pygitstatus/prompt.py @@ -97,3 +97,13 @@ def tag(fld: PromptField, ctx: PromptFields): if head_commit == tag_commit: fld.value = _tag.partition('refs/tags/')[-1] break + + +@PromptField.wrap(prefix="…", info="untracked") +def untracked(fld: PromptField, ctx: PromptFields): + with contextlib.suppress(GitError): + fld.value = '' + repo = Repo('.') + untracked_count = len([v for k, v in repo.status().items() if v == GIT_STATUS_WT_NEW]) + if untracked_count > 0: + fld.value = str(untracked_count)