GithubHelp home page GithubHelp logo

aignas / git-prompt-rs Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 81 KB

A small CLI to print useful info about the current git repository.

Home Page: https://asciinema.org/a/RlvQkQ57HZ6Pcw7pNlvuLAfjd

License: MIT License

Rust 88.41% Makefile 8.78% Ruby 2.80%

git-prompt-rs's Introduction

Git prompt

Build Status dependency status

This is a small CLI to display git info based on the current directory.

Features

  • When counting the commit difference between the remote and the local clone it will default to the master on the remote if a branch with the same name is not found. The default is customizable.

  • It will make sure that the last character of the prompt is a space. Some shells break because of this.

Example output:

Install

ArchLinux

$ git clone https://aur.archlinux.org/git-prompt-rs.git ${HOME}/aur/git-prompt-rs-git
$ cd ${HOME}/aur/git-prompt-rs-git
$ makepkg -si

Mac

$ brew tap aignas/git-prompt-rs https://github.com/aignas/git-prompt-rs.git
$ brew install git-prompt-bin

Build

For the time being build with cargo:

$ mkdir -p ${HOME}/bin # Ensure that this is in your path
$ cd .../git_prompt
$ cargo -Z unstable-options build --release --out-dir "${HOME}/bin"

Setup

ZSH

More info can be found at ZSH documentation prompt expansion section.

precmd() {
  local git_info=<path to the executable>
  export PS1="%F{blue}%~%f $(exec ${git_info})
%F{magenta}❯%f "
}

Contribute

Pull requests are welcome.

Tests with large repos

One of the larger repos I could find on the internet is for Chromium and I did shallow clone the repo on my local machine by:

$ git clone -b master [email protected]:chromium/chromium.git --depth=1

Some stats about the repo:

$ git ls-files | wc -c
27032106

Then I ran my benchmarks with the chromium repo (ThinkPad T420s with an SSD):

$ GIT_PROMPT_BENCH_PATH=~/src/github/chromium cargo bench
branch_status           time:   [119.97 us 120.68 us 121.52 us]
repo_status             time:   [21.080 us 21.137 us 21.212 us]
local_status            time:   [2.3654 s 2.3905 s 2.4161 s] # This is even more than doing git status from the shell!

This shows that the local_status is indeed the major offender here, which is expected and documented well in the README in romkatv/gitstatus. The thing is that git status is always going to be the bottleneck in case of larger repositories, because the CLI needs to scan through all committed files and the best way to optimize this path is to:

  1. do less kernel calls when scanning.
  2. do less scanning.

Do less kernel calls when scanning

We could employ a server/client architecture in order to only do the necessary scanning. Possible ways to improve this:

Just use git status

After a bit of thought, I realized, that git status is the solution I am looking for. It is fast and it works well with any other tooling that I may use:

  • Git VFS
  • watchman

And the best of all, it works with large repos and I do not need to maintain code. The only thing I do need to do is to setup the git hooks to ensure that the watchman is used.

git-prompt-rs's People

Contributors

aignas avatar

Stargazers

 avatar

Watchers

 avatar  avatar

git-prompt-rs's Issues

Symbol-schemes

In order to have a bit more customisability for users, who want to use non-standard fonts (e.g. Fira Code or any powerline patched font) there should be a way to specify symbols, keywords for the CLI.

User stories:

  • As a user I want to be able to override local status symbols
  • As a user I want to be able to override ahead/behind status symbols

Optional user stories:

  • As a user I want to be able to override keywords used to print everything.

Example output

In order to show what this can do, the CLI needs to be able to display examples.

Stories:

  • As a developer I want to have a compact representation of the example.
  • As a user I want to be able to specify different symbol-schemes.
  • As a user I want to be able to specify different color-schemes.
  • As a user I want to see those examples on the web and when I run the CLI myself.

Optional stories:

  • As a user I want to be able to compare them side by side.

Tests with mocks

As a user I want to have tests with a repository mock. This serves as a way to learn new things.

User stories:

  • As a developer I want to learn how to use simulacrum in the project.
  • As a developer I want to be able to have easier end-to-end tests.
  • As a developer I want to have error handling tests.

Stashed entries

As shown in bash-git-prompt we could have a way to show stashed entries.

User stories:

  • As a user I want to see the number of items in stash.

Related to #3 because of extra symbols being used.

Color-scheme

In order to make the CLI customisable, there should be a way to specify the color-schemes.

User stories:

  • As a user I want to be able to pass the collors as a CLI parameter.
  • As a user I want to have presets to select from.
  • As a user I want to know how to easily contribute color new schemes.
  • As a user I want to have 256 color support
    - [ ] As a user I want to have true-color support

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.