{"id":15687439,"url":"https://github.com/danielparks/git-status-vars","last_synced_at":"2025-05-07T19:46:41.686Z","repository":{"id":57750651,"uuid":"525305652","full_name":"danielparks/git-status-vars","owner":"danielparks","description":"Summarize git repo info into shell variables (for use in a prompt)","archived":false,"fork":false,"pushed_at":"2025-03-04T21:53:10.000Z","size":307,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T12:46:14.874Z","etag":null,"topics":["bash-prompt","git","prompt","shell","shell-prompt","zsh-prompt"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielparks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-16T09:08:03.000Z","updated_at":"2025-03-04T21:53:14.000Z","dependencies_parsed_at":"2025-03-11T11:33:08.179Z","dependency_job_id":"3bd4b7db-cf29-40e5-85ce-dc0bbc51322e","html_url":"https://github.com/danielparks/git-status-vars","commit_stats":{"total_commits":89,"total_committers":2,"mean_commits":44.5,"dds":0.0674157303370787,"last_synced_commit":"c6e7cb37eddae56490032022a515d19eb3c4750b"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fgit-status-vars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fgit-status-vars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fgit-status-vars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielparks%2Fgit-status-vars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielparks","download_url":"https://codeload.github.com/danielparks/git-status-vars/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252947918,"owners_count":21830052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash-prompt","git","prompt","shell","shell-prompt","zsh-prompt"],"created_at":"2024-10-03T17:48:27.448Z","updated_at":"2025-05-07T19:46:41.661Z","avatar_url":"https://github.com/danielparks.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Summarize git repo info into shell variables\n\nThis is designed to replace multiple calls to `git` with a single use of\n`eval $(git-status-vars)`. It’s especially useful for generating a shell prompt.\n\nThis is intended to be generally usable in any theme that wants to report git\ninformation in any shell with `sh`-like strings. I use it in my [personal ZSH\ntheme](https://github.com/danielparks/danielparks-zsh-theme).\n\n## Installation\n\nYou can download binaries from the [GitHub releases page][releases]. Just\nextract them and copy the file inside into your `$PATH`, e.g. `/usr/local/bin`.\nThe most common ones are:\n\n  * Linux: [x86-64](https://github.com/danielparks/git-status-vars/releases/latest/download/git-status-vars-x86_64-unknown-linux-gnu.tar.gz),\n    [ARM](https://github.com/danielparks/git-status-vars/releases/latest/download/git-status-vars-aarch64-unknown-linux-musl.tar.gz)\n  * macOS: [Intel](https://github.com/danielparks/git-status-vars/releases/latest/download/git-status-vars-x86_64-apple-darwin.tar.gz),\n    [Apple silicon](https://github.com/danielparks/git-status-vars/releases/latest/download/git-status-vars-aarch64-apple-darwin.tar.gz)\n  * [Windows on x86-64](https://github.com/danielparks/git-status-vars/releases/latest/download/git-status-vars-x86_64-pc-windows-msvc.zip)\n\nIf you have `cargo`, you can just do `cargo install git-status-vars` to install\nfrom source, or if you’ve installed [`cargo binstall`][binstall] you can use\nthat (`cargo binstall git-status-vars`).\n\n[![Release status](https://github.com/danielparks/git-status-vars/actions/workflows/release.yaml/badge.svg)](https://github.com/danielparks/git-status-vars/actions/workflows/release.yaml)\n\n## Usage\n\n```sh\neval $(git-status-vars 2\u003e/dev/null)\nif [[ $repo_state == \"NotFound\" ]] ; then\n  return 0\nfi\n```\n\nThis outputs a bunch of `sh` compatible environment variables about the current\nrepository. The repository is found by looking at each of the following in order\nand taking the first that matches:\n\n  1. Command line parameter. A repository directory, or a subdirectory of a\n     repository, may be passed on the command line.\n  2. The `$GIT_DIR` environment variable, just like `git`.\n  3. A `.git` directory in the working directory or one of its parents.\n\n`git-status-vars` will always output `repo_state=`, but all other variables may\nbe left out. In particular, if it can’t find a repository, it will output only\n`repo_state=NotFound`.\n\n### Example prompt function with `git-status-vars`\n\n```sh\ngit_prompt () {\n  eval $(git-status-vars 2\u003e/dev/null)\n  if [[ $repo_state == \"NotFound\" ]] ; then\n    return 0\n  fi\n\n  local fg_color=green\n  if (( $untracked_count \u003e 0 )) ; then\n    fg_color=red\n  fi\n\n  local ref=$head_ref1_short\n  if [[ -z $ref ]] ; then\n    ref=${head_hash:0:8}\n  fi\n\n  print -Pn \"%F{$fg_color}${ref}%f \"\n}\n```\n\n### Equivalent prompt function without `git-status-vars`\n\n```sh\ngit_prompt () {\n  setopt local_options pipefail\n  local untracked_count fg_color=green\n  untracked_count=$(git ls-files --other --exclude-standard 2\u003e/dev/null | wc -l)\n  if (( $? != 0 )) ; then\n    # No repository\n    return 0\n  fi\n\n  local fg_color=green\n  if (( $untracked_count \u003e 0 )) ; then\n    fg_color=red\n  fi\n\n  # Try for the branch or tag name, then try for the commit hash\n  ref=$(git symbolic-ref --short HEAD 2\u003e/dev/null) \\\n    || ref=\"$(git show-ref --head --hash --abbrev HEAD 2\u003e/dev/null | head -n1)\"\n\n  print -Pn \"%F{$fg_color}${ref}%f \"\n}\n```\n\n### Typical output\n\n```\n~/projects/git-status-vars ❯ git-status-vars\nrepo_state=Clean\nrepo_workdir=/Users/daniel/projects/git-status-vars/\nrepo_empty=false\nrepo_bare=false\nhead_ref_length=1\nhead_ref1_name=refs/heads/main\nhead_ref1_short=main\nhead_ref1_kind=direct\nhead_ref1_error=''\nhead_hash=2df6b768e60fbf899d8c8dc4a20385f30ee5da24\nhead_ahead=0\nhead_behind=0\nhead_upstream_error=''\nuntracked_count=0\nunstaged_count=0\nstaged_count=0\nconflicted_count=0\nstash_count=0\n~/projects/git-status-vars ❯ cd /\n/ ❯ git-status-vars\nrepo_state=NotFound\n```\n\n## Performance\n\n`git-status-vars` is generally faster than multiple calls to `git`, though `git`\nis fast enough that the difference will not usually be perceptible. On my laptop\n`git-status-vars` typically runs in around 8 ms whereas the fallback code\ninvolving multiple calls to `git` takes around 25 ms.\n\nI have not tested this on large repositories.\n\n## Rust Crate\n\n[![docs.rs](https://img.shields.io/docsrs/git-status-vars)][docs.rs]\n[![Crates.io](https://img.shields.io/crates/v/git-status-vars)][crates.io]\n![Rust version 1.64+](https://img.shields.io/badge/Rust%20version-1.64%2B-success)\n\nI’m not sure how useful it is, but this may be used from other Rust code.\n\nCurrently the minimum supported Rust version (MSRV) is **1.74.1**.\n\n## Development and contributions\n\nSee [DEVELOPMENT.md](DEVELOPMENT.md) for notes on contributing to this repo,\nthe license, how changes are tracked, and how releases are made.\n\n### Development status\n\nThis is stable. I don’t have plans for additional features, but if you have\nideas please either submit an [issue][] or a [pull request][].\n\nI will periodically update this to ensure that it doesn’t bit rot as\ndependencies are updated, but you should not expect active development.\n\n[binstall]: https://github.com/cargo-bins/cargo-binstall\n[crates.io]: https://crates.io/crates/git-status-vars\n[docs.rs]: https://docs.rs/git-status-vars/latest/git_status_vars/\n[releases]: https://github.com/danielparks/git-status-vars/releases\n[issue]: https://github.com/danielparks/git-status-vars/issues\n[pull request]: https://github.com/danielparks/git-status-vars/pulls\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielparks%2Fgit-status-vars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielparks%2Fgit-status-vars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielparks%2Fgit-status-vars/lists"}