Giter Site home page Giter Site logo

githud's Introduction

Build Status Release Hackage Hackage

As you might have guessed from its name, githud is a heads up display for the command line that will show git information. The focus is on information and performance.

If you are as crazy as I am about your prompt, you might want to check my somewhat related project envstatus

Example See Prompt explained for a detailled element by element description of what you see

Note: this example is taken from the iTerm2 OSX terminal, with custom colors from the Solarized Dark theme

Why githud?

I was really psyched a few months ago (mid-2015) by git-radar. Git-radar does the exact same thing as githud, but is implemented in shell. While I had a great time using it for a while, I realized that on my particular setup, git-radar was introducing a visible delay (>200ms, too long for me) in the displaying of my prompt.

At that time, I was looking for an exercise to implement in Haskell, so that's how I created githud

Install

Whichever way you install githud, don't forget to complete the Setup

Mac OSX with brew

(Maintained on each release)

  • link my tap
brew tap gbataille/homebrew-gba
  • install githud
brew install githud

Binary packages on linux

Looking for contributor to provide a recipe (in github actions form?)

With cabal and Nix

(Used in the development process, therefore it is maintained and up-to-date)

A Nix config is maintained in compatibility with the cabal file. So to be sure to use a compatible ghc version, and corresponding libraries, just

nix-shell
cabal v2-install

With Stack

(Not maintained. Dev happens using Nix + Cabal. Don't hesitate to contribute)

Stack is a haskell package manager. 1 command install can be found here

githud is available on hackage, but some dependencies have to be explicited. You need to add the following to the extra-deps in your stack.yml file

extra-deps:
- daemons-0.4.0
- network-2.8.0.1

then you can run

stack install githud

With Cabal

(Not maintained. Dev happens using Nix + Cabal. Don't hesitate to contribute)

githud is available on hackage. Therefore just get it as usual

cabal v2-install exe:githud

You can then update your path to include your installation directory (typically ~/.cabal/bin) or copy the installed executable to a common location like /usr/local/bin

Setup

If you simply call the githud executable, you'll get a short status of your repository. It's meant to be called each time you display your prompt. Therefore you want to put it in your PS1 env variable.

Shells have some fancy way of managing prompt when you do things like autocompletion and the like. For that it needs to know the size of the prompt. Special characters used to express the color of the prompt need to be surrounded by special markup for them not to be counted.

GitHUD knows how to handle this. All you have to do is to run the program with a parameter depending on your shell of choice and those special characters will be used in the output

Bash

githud bash

For example, in my .bashrc file, with the executable at /usr/local/bin/githud, I have a prompt definition that looks like that:

export PS1="\[\033[0;37m\][\A]\[\033[0m\] \[\033[0;36m\]\u\[\033[0m\]
\W\[\033[0;32m\]\$(/usr/local/bin/githud bash)\[\033[0m\]\$ "

(it has a lot more things into it, including the current directory, the hour, and a prompt '$' terminating character)

ZSH

githud zsh

Note: Those special characters %{ %} are only interpreted and hidden when zsh renders a prompt. If you simply call githud with this parameter 'zsh' from the command line, you'll see them in the output!

Putting it together in my .zshrc, I have the following PROMPT variable with the executable at /usr/local/bin/githud

setopt PROMPT_SUBST
export PROMPT='%F{white}%T%F{cyan} %n%{$reset_color%} $(/usr/local/bin/githud zsh) $'

(it has a lot more things into it, including the current directory, the current user, the hour, and a prompt '$' terminating character)

Fish

Add this code to your config.fish file.

function fish_prompt
  set_color white
  echo -n [(date "+%H:%M")]
  set_color cyan
  echo -n (whoami):
  set_color yellow
  echo -n (prompt_pwd)
  set_color $fish_color_cwd
  echo -n (/usr/local/bin/githud)
  set_color normal
  echo -n "> "
end

TMUX

Proposed by @Thermatix

githud tmux

Putting it together in my .tmux.conf, I have the following status-right variable with

set -g status-right '#{pane_current_command} #(~/.zsh/bin/githud_status "#{pane_current_path}")'

which necessitates a small script ~/.zsh/bin/githud_status

#!/usr/local/bin/zsh -f
cd $1 && /usr/local/bin/githud zsh

and the executable at /usr/local/bin/githud

NONE

Proposed by @Thermatix

You can get a raw text output (no special formatting) by calling

githud none

Configuration

The prompt format is nicely configurable. The defaults give you the look and feel from the screenshot above, with a terminal configured with the Solarized Dark theme colors.

To change those colors, or the markers used in the prompt:

  • Copy the .githudrc file from this repository into your home directory. Then, from your home directory
wget https://raw.githubusercontent.com/gbataille/gitHUD/master/.githudrc
  • Edit the file by uncommenting some fields and changing their values (instructions are enclosed in the file)

You can control which section of the output are shown (if you want to mask some) with the configuration keys starting with "show_part_"

The fetcher daemon

githud includes a companion daemon called githudd. This daemon will start the first time githud is invoked and will run forever.

This daemon will simply execute a git fetch periodically in the last git repository in which githud was executed. In the standard installation where you use githud in your prompt, this means that the daemon executes git fetch in the last git repository visited.

The .githudrc configuration file can contain the following configuration for the daemon (default values given here)

# Whether githud will launch the background daemon
run_fetcher_daemon=True
# How long does the daemon sleep between cycles
githudd_sleep_seconds=30
# Path where the githudd pid file will be stored. Needs to exist and be accessible by the current
# user
githudd_pid_file_path=/usr/local/var/run/githudd.pid
# Path where the githudd lock file will be stored. Needs to exist and be accessible by the current
# user
githudd_lock_file_path=/$TMPDIR/githudd.lock
# Path where the githudd socket file will be stored. Needs to exist and be accessible by the current
# user
githudd_socket_file_path=/usr/local/var/run/githudd.socket
# Path where the githudd stdout/stderr capture logfile will be store.
# Githudd logs can be verbose. They are here for debugging only. It is not advised that you
# activate them
# Use the value /dev/null to disable the logs
githudd_log_file_path=/dev/null

To stop the daemon, you can simply do

pkill githudd

Note that due to instability, the daemon is currently disabled by default

The health of the githudd daemon is indicated by a red hearth (broken when unhealthy) at the start of the prompt (only when the daemon is activated)

Understanding the githud prompt

See Prompt explained

Benefits

  • githud is fast (on my system, about twice as fast as git-radar, with exec times below 100ms)
  • githud is easily maintainable through proper test coverage

The only downside compared to git-radar is that you need to compile it on your platform, as opposed to being just shell.

On Mac, it's now easy since I packaged it as a brew bottle. For Linux, I'm waiting for contributions to put it in RPM or DEB packages :)

Benchmarks

So of course, I wanted to check that whatever I was doing was useful. So I did a couple of benchmarks with the Haskell Criterion library. It's based on my system and does not guarantee any performances but it gives you an idea of the improvements. Here goes:

  • git-radar - full shell implementation
  • githud-syncIO - with normal IOs done one at a time
  • githud-asyncIO - with IOs programmed asynchronously for better performance.

Bench

Here you can find the details

For information: I ran that on a Macbook Pro 13", 2014, fully boosted, running with iTerm 2, tmux, oh-my-zsh, inside a git repo with quite some information to parse

Thanks

Well, my thanks to git-radar for the great idea, and to guibou for the code reviews

githud's People

Contributors

gbataille avatar guibou avatar jlesquembre avatar rfldn avatar superstrong avatar voidus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

githud's Issues

kill githudd on release

  • Automate with brew if possible
  • for other users, document
  • (nice to have) githudd detects (shasum?) that it's out-of-date and suicide itself

Does nothing, shows nothing

$ githudd none
$ githudd zsh
$ githudd bash

None of these commands show anything. The terminal prompt is empty.

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	cabal.project.freeze
	dist-newstyle/

nothing added to commit but untracked files present (use "git add" to track)

Doesn't display correctly inside of tmux

So, I created a zsh script:

#!/usr/local/bin/zsh -f
cd $1 && githud zsh

so I can then do this inside of tmux:

set -g pane-border-format '#{pane_current_command} #(~/.zsh/bin/githud_status "#{pane_current_path}")'

but it displays like this:
alt with zsh

and even if I try it with bash or with nothing it shows like this:
alt without zsh

Githud sometimes fail silently

githudd has errors
githud fails too, but silently if in the prompt
need to manually remove the socket and pid file. Possibly due to a network connection drop/change to the internet

gbataille ~…s/Prog/MyConfig [1] $ githud                                                                        7:36 ⤬
githudd: fdRead: end of file (EOF)
githud: callProcess: githudd "/Users/gbataille/Documents/Prog/MyConfig" (exit 1): failed
  • githud should not fail on githudd failing
  • githud should not fail if there is a problem with the socket
  • githudd should not fail (when?)
  • githud should have a marker warning that githudd is broken or some way to notify the user
  • draw the thread / socket interaction in UML

detached process are not killed and consume bandwidth

I had processes that consume bandwidth, after investigation they are create by githudd detached processes:
-+= 00001 root /sbin/launchd
|-+- 71284 pke githudd /Users/pke/myrepo
| -+- 97514 pke git fetch
| --- 97515 pke /usr/bin/ssh [email protected] git-upload-pack '/myrepo.git'

$ ps -edf | grep hud | wc -l
85

Some of those process were started one month ago.

After killing all the pending githudd, my bandwidth radically decreased:
image

Feature request: handle tags

I started to use gitHUD a week ago and I find it really useful. Thanks for writing it!

But there is a feature I'm missing, when I checkout a tag, I see [detached@c83f14e]. Before I was using the default fishshell functionally to show git information, and in that case I had something like (v1.0). What do you think about showing [[email protected]] when you checkout a tag?

brew install `setup_ghc_compilers'

brew install githud
Error: undefined local variable or method setup_ghc_compilers' for #<Class:0x007fbc0b085038> Please report this bug: https://git.io/brew-troubleshooting /usr/local/Library/Taps/gbataille/homebrew-gba/Formula/githud.rb:15:inclass:Githud'
/usr/local/Library/Taps/gbataille/homebrew-gba/Formula/githud.rb:3:in load_formula' /usr/local/Library/Homebrew/formulary.rb:23:inmodule_eval'
/usr/local/Library/Homebrew/formulary.rb:23:in load_formula' /usr/local/Library/Homebrew/formulary.rb:36:inload_formula_from_path'
/usr/local/Library/Homebrew/formulary.rb:85:in load_file' /usr/local/Library/Homebrew/formulary.rb:76:inklass'
/usr/local/Library/Homebrew/formulary.rb:72:in get_formula' /usr/local/Library/Homebrew/formulary.rb:207:infactory'
/usr/local/Library/Homebrew/formulary.rb:352:in find_with_priority' /usr/local/Library/Homebrew/extend/ARGV.rb:20:inblock in formulae'
/usr/local/Library/Homebrew/extend/ARGV.rb:16:in map' /usr/local/Library/Homebrew/extend/ARGV.rb:16:informulae'
/usr/local/Library/Homebrew/cmd/install.rb:45:in install' /usr/local/Library/brew.rb:143:in

'

Format for standalone branches is not ideal

I have a gh-pages branch that is not tied to master. Following is what githud looks like for me:

ᚴ 𝘮 338⇄338 [gh-pages] 24A31D

Notice the whole thing about comparing my branch to master. In this case that is just noise because this branch has nothing to do with master. Would be awesome for branches like this to just skip that info. Of course if I make a branch in gh-pages, it would also be cool if it included this treatment relative to the base branch.

brew install doesn't work on M1 due to GHC version

Seems like the GHC 8.8 dependency is not compatible with M1 macbooks. This can probably be fixed with using a later version such as 8.10.x or 9.x which the developers say is stable on the M1 and available as a bottle.

Failed Install

$ brew install githud

==> Downloading https://ghcr.io/v2/homebrew/core/python/3.9/manifests/3.9.13_1
Already downloaded: /Users/derek/Library/Caches/Homebrew/downloads/874a1eda6b1ec5f181fd49612cff538012a071e86355c55174d01f3eb6d3fe96--python@3.9-3.9.13_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.9/blobs/sha256:2e02d1c12a0baecc8b1af05701c7db8038e6b9a7bf453cc4
Already downloaded: /Users/derek/Library/Caches/Homebrew/downloads/c31e2636906b2ecbca22aea377baa370b942747cabe5b0ceac48379f21ec9556--python@3.9--3.9.13_1.arm64_monterey.bottle.tar.gz
==> Downloading https://ghcr.io/v2/homebrew/core/llvm/12/manifests/12.0.1_1
Already downloaded: /Users/derek/Library/Caches/Homebrew/downloads/146953ef4e3ea1c597c1b9eec7399d450f3f2af9b218c74e6c95fe21029623e7--llvm@12-12.0.1_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/llvm/12/blobs/sha256:11c9ec1e717ef4ad5d4a42623bd870172fef6bbc7dc42a4877c
Already downloaded: /Users/derek/Library/Caches/Homebrew/downloads/3acf656f37a043fd9f8522284b1740cbf40b54ea566aa35ce0208f285eae5971--llvm@12--12.0.1_1.arm64_monterey.bottle.tar.gz
==> Downloading https://ghcr.io/v2/homebrew/core/ghc/manifests/8.10.7_1
Already downloaded: /Users/derek/Library/Caches/Homebrew/downloads/a2057ce5a3eaf6dfa0dcf6eb046c3a7c87f28c73ccde6357cdc25f7de347e450--ghc-8.10.7_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ghc/blobs/sha256:41e846a0479f930390ae2c65cf7ae0f3ea3755ff26df56822fb9997
Already downloaded: /Users/derek/Library/Caches/Homebrew/downloads/0be9dedd0cfa2f78654c7a487776c3dc97a2fc2c7e5d0a1e7fe7e637f9139245--ghc--8.10.7_1.arm64_monterey.bottle.tar.gz
==> Downloading https://ghcr.io/v2/homebrew/core/cabal-install/manifests/3.6.2.0
Already downloaded: /Users/derek/Library/Caches/Homebrew/downloads/3d6e582669343868b997495e02a65b5fd279805c4c6395917ac443f8f5dfc579--cabal-install-3.6.2.0.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/cabal-install/blobs/sha256:1567f1329f94935dce0e58a095e0551a0e40f183f1c82
Already downloaded: /Users/derek/Library/Caches/Homebrew/downloads/cd7ae174be8bf12fc780b9048503bf0ce9ee7becd9b5d81455791fd4d8c9b7d1--cabal-install--3.6.2.0.arm64_monterey.bottle.tar.gz
Error: [email protected]: no bottle available!
You can try to install from source with:
  brew install --build-from-source [email protected]
Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.

GHC 8.10 is available for M1

$ brew info ghc

ghc: stable 8.10.7 (bottled)
Glorious Glasgow Haskell Compilation System
https://haskell.org/ghc/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ghc.rb
License: BSD-3-Clause and (LGPL-3.0-or-later or GPL-2.0-or-later)
==> Dependencies
Build: [email protected] ✘, sphinx-doc ✘
Required: llvm@12 ✘
==> Analytics
install: 1,811 (30 days), 5,786 (90 days), 43,715 (365 days)
install-on-request: 1,008 (30 days), 3,311 (90 days), 25,683 (365 days)
build-error: 19 (30 days)

Install help for Haskell newbie

Hi!
I have worked with a number of other programing languages, but Haskell is new to me. I tried the following on Ubuntu Linux 16.04 to install gitHUD:

sudo apt-get install cabal-install haskell-platform ghc
cabal update
cabal install gitHUD

This last command returns the following output:

Resolving dependencies...
cabal: Could not resolve dependencies:
trying: gitHUD-1.3.5
rejecting: base-4.6.0.1/installed-8aa... (conflict: gitHUD => base>=4.7 && <5)
rejecting: base-4.9.1.0, 4.9.0.0, 4.8.2.0, 4.8.1.0, 4.8.0.0, 4.7.0.2, 4.7.0.1,
4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0, 4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0,
4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0, 4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global
constraint requires installed instance)

Compiler version is:

haskell-compiler --version
The Glorious Glasgow Haskell Compilation System, version 7.6.3

I see it is a dependency issue but I am not sure what to do to resolve this issue. I thought that cabal was a dependency manager but maybe it is not. A point in the correct direction would be appreciated.
Thanks in advance for any help you can provide!
Frederick

Change the name to githud

It is a common convention that binaries have lower-case names. While gitHUD looks nice, some linux distros (namely arch) prohibit package names like gitHUD.

ZSH prompt does not update after initial sourcing

Excited to get this fully set up!

I've followed the instructions for installing with ZSH with these steps:

  • brew tap gbataille/homebrew-gba
  • brew install githud

Added this to my ~/.zshrc:

  • export PROMPT="%{$fg_bold[white]%}%T%{$reset_color%}%{$fg[cyan]%} %n%{$reset_color%} $(/usr/local/bin/githud zsh) $ "

I've confirmed there's an executable at /usr/local/bin/githud.

If I manually run /usr/local/bin/githud zdh it echoes the correct status, but then returns to the old prompt. Here's an example, where I'm actually on the branch core-dev but it still shows me on frame-success-master:

23:35 robbie ᚴ [frame-success-master] $ /usr/local/bin/githud zsh
%{%}ᚴ [%{%}core-dev%{%}]
23:35 robbie ᚴ [frame-success-master] $

Am I missing something in getting it to refresh every time the prompt loads?

Make background color transparent or customizable

I'm migrating from git-radar to gitHUD (while git-radar is no longer being maintained).

In my ZSH theme I have a colored bar where I like to put my Git status:
screen shot 2016-08-15 at 10 12 03

With gitHUD, the background seems to be hardcoded:
screen shot 2016-08-15 at 10 20 35

I would love for it to be transparent or if that is not possible, customizable (also, there seems to be a trailing space after the last component).

Seems to calculate PS1 length incorrectly

Whatever magic that needs to happen to tell bash to ignore certain sequences of characters when defining PS1 (in bash typically \[\]) doesn't seem to happen for gitHUD. This means my terminal calculates the line length incorrectly. I think the following demonstrates the issue (should be 24 characters long, but instead shows 75):

> export test=$(gitHUD)
> echo ${test}
𝘮 40⇄29 [develop] 5↓ 28≡
> echo ${#test}
75

Does not handle dual state file

If a file is both modified in the index AND locally, it shows only one of the 2.
I have to parse the status output twice with 2 types of matchers

brew install takes hours and hours

I left it overnight and it's still running. I can compile my entire Gentoo operating systems in less time. It's hard to promote this if ghc takes an absurd amount of time to compile.

Is there an easier way of installing it?

I'm surprised there isn't a native precompiled (bottle) install via homebrew for macOS versions.

Automate release

Script the release process:

  • bumping the version
  • building
  • publishing to hackage
  • updating the brew formula

Does gitHUD properly display the Dull colour intensity?

Hi Gregory! Thanks for building this fast alternative to git-radar! 😄 It's really helpful.

I have a question: I'm trying to configure some of the colours to be "Dull", but I'm not noticing any affect. It appears to me that gitHUD prints all colours as "Vivid", regardless of the config. Do you mind testing this on your end to see if you can reproduce it? I'm using zsh on macOS, I reproduced the issue on a minimal config. Please let me know what you think, thanks!

Fix tap compatibility with Big Sur

Linking the tap currently fails on Big Sur

% brew tap gbataille/homebrew-gba
==> Tapping gbataille/gba
Cloning into '/usr/local/Homebrew/Library/Taps/gbataille/homebrew-gba'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 259 (delta 5), reused 22 (delta 5), pack-reused 235
Receiving objects: 100% (259/259), 18.34 MiB | 8.88 MiB/s, done.
Resolving deltas: 100% (71/71), done.
Error: Invalid formula: /usr/local/Homebrew/Library/Taps/gbataille/homebrew-gba/Formula/envstatus.rb
envstatus: Calling include Language::Haskell::Cabal is disabled! There is no replacement.
Please report this issue to the gbataille/gba tap (not Homebrew/brew or Homebrew/core):
  /usr/local/Homebrew/Library/Taps/gbataille/homebrew-gba/Formula/envstatus.rb:4

Error: Cannot tap gbataille/gba: invalid syntax in tap!

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.