|
| 1 | +# gitstatus |
| 2 | +**gitstatus** is a lightweight tool for querying the status of git repos for the use in interactive tools. |
| 3 | + |
| 4 | +The primary motivation is to be able to use git status in shell prompt without suffering terrible latency that all other solutions impose. |
| 5 | + |
| 6 | +When using common tools such as [vcs_info](http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#vcs_005finfo-Quickstart) to embed git status in shell prompt, latency is high for two main reasons: |
| 7 | + |
| 8 | + 1. About a dozen processes are created to generate a prompt. Creating processes and pipes to communicate with them is expensive. |
| 9 | + 2. There is a lot of redundancy between different `git` commands that get called. For example, every command has to scan parent directories in search of `.git`. Many commands have to resolve HEAD. Some have to read index. |
| 10 | + |
| 11 | +**gitstatus** solves this problem by assembling all information that the prompt needs in a single process and presenting it in an easy-to-parse format. It's using [libgit2](https://libgit2.org/) under the hood for heavy lifting. |
| 12 | + |
| 13 | +## Requirements |
| 14 | + |
| 15 | +* To compile: C++17 compiler, GNU make, libgit2. |
| 16 | +* To run: Linux, GNU libc. |
| 17 | + |
| 18 | +## Compiling |
| 19 | + |
| 20 | +For best results, compile libgit2 statically with all optional features disabled and all required feature bundled. |
| 21 | + |
| 22 | +```shell |
| 23 | +git clone https://github.com/libgit2/libgit2.git |
| 24 | +cd libgit2 |
| 25 | +mkdir build |
| 26 | +cd build |
| 27 | +cmake \ |
| 28 | + -DUSE_SSH=OFF \ |
| 29 | + -DUSE_HTTPS=OFF \ |
| 30 | + -DTHREADSAFE=OFF \ |
| 31 | + -DBUILD_SHARED_LIBS=OFF \ |
| 32 | + -DUSE_EXT_HTTP_PARSER=OFF \ |
| 33 | + -DUSE_BUNDLED_ZLIB=ON \ |
| 34 | + -DSHA1_BACKEND=Generic \ |
| 35 | + -DCMAKE_BUILD_TYPE=Release \ |
| 36 | + .. |
| 37 | +make VERBOSE=1 -j 20 |
| 38 | +sudo make install |
| 39 | +``` |
| 40 | + |
| 41 | +Then build gitstatus itself. |
| 42 | + |
| 43 | +```shell |
| 44 | +git clone git@github.com:romkatv/gitstatus.git |
| 45 | +cd gitstatus |
| 46 | +make |
| 47 | +``` |
| 48 | + |
| 49 | +## Prebuilt Binaries |
| 50 | + |
| 51 | +If you don't feel like building from sources, you can grab a statically built ELF binary for x64 with a dynamic dependency on glibc 6 from [Releases](https://github.com/romkatv/gitstatus/releases). |
| 52 | + |
| 53 | +## Using Manually |
| 54 | + |
| 55 | +Run `gitstatus --help` for help or read the same thing in [gitstatus.cc](https://github.com/romkatv/gitstatus/blob/master/src/gitstatus.cc). |
| 56 | + |
| 57 | +## Using with Powerlevel9k |
| 58 | + |
| 59 | +If you are using the awesome [Powerlevel9k](https://github.com/bhilburn/powerlevel9k) ZSH theme, you can configure the existing `vcs` prompt to use gitstatus for a massive reduction in latency. |
| 60 | + |
| 61 | +First, use [this fork](https://github.com/romkatv/powerlevel9k/tree/caching) of Powerlevel9k instead of the official release. This fork also enables caching, which speeds up prompt rendering by over 10x. Note that you need to use branch `caching`. |
| 62 | + |
| 63 | +```shell |
| 64 | +# Assuming oh-my-zsh at the standard location. |
| 65 | +rm -rf ~/.oh-my-zsh/custom/themes/powerlevel9k |
| 66 | +git clone -b caching git@github.com:romkatv/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k |
| 67 | +``` |
| 68 | + |
| 69 | +Then set the following configuration options in your `.zshrc` before sourcing Powerlevel9k. |
| 70 | + |
| 71 | +``` |
| 72 | +# Enable caching of parts of the prompt to make rendering much faster. |
| 73 | +POWERLEVEL9K_USE_CACHE=true |
| 74 | +
|
| 75 | +# Enable alternative implementation for the vcs prompt. It's much faster but it only supports git. |
| 76 | +# Tell it to not scan for dirty files in repos with over 1k files. |
| 77 | +POWERLEVEL9K_VCS_STATUS_COMMAND="$HOME/bin/gitstatus --dirty-max-index-size=1024" |
| 78 | +``` |
| 79 | + |
| 80 | +Lastly, put `gitstatus` binary in your `~/bin`. |
| 81 | + |
| 82 | +You can check out my [dotfiles-public](https://github.com/romkatv/dotfiles-public) repo for details. |
| 83 | + |
| 84 | +## License |
| 85 | + |
| 86 | +GNU General Public License v3.0. See [LICENSE](https://github.com/romkatv/gitstatus/blob/master/LICENSE). |
0 commit comments