
A heads up display for git - michaelallen
https://github.com/michaeldfallen/git-radar
======
an_ko
I use a modified version of mislav's git prompt
[https://gist.github.com/mislav/1712320](https://gist.github.com/mislav/1712320)
which is pretty minimal but usually enough for me.

For when I have to wrangle lots of files at once (like during interactive
rebase to clean up history before push) I have a _git watch_ alias that shows
a high-level overview of changes that refreshes with inotify:

    
    
      [alias]
          watch = "!clear;inotifywait --quiet -mr -e modify,move,create,delete --format \"%f %e\" @/.git . | \
      while read file; do \
          clear;\
          git status --short;\
          git --no-pager diff --shortstat;\
      done;"
    

I leave that running in a visible terminal window. It's more verbose than a
prompt and reduces the need for constant _git status_ sanity-checking. Maybe
useful for someone.

~~~
mendelk
How would this need to be changed to work on osx?

~~~
ianlevesque
Just need to replace inotifywait with an FSEvents-based change watcher.

~~~
sulam
watchman
([https://github.com/facebook/watchman](https://github.com/facebook/watchman))
is cross platform.

------
metasean
For anyone interested in putting together their own version, I customized my
bash terminal (including git related info) using the following resources:

\- Mikko Nylén's comment in
[http://web.archive.org/web/20130127054804/http://asemanfar.c...](http://web.archive.org/web/20130127054804/http://asemanfar.com/Current-
Git-Branch-in-Bash-Prompt)

\- [http://stackoverflow.com/questions/8120553/bash-profile-
sett...](http://stackoverflow.com/questions/8120553/bash-profile-setting-not-
working-for-path-ps1)

\- [http://volnitsky.com/project/git-
prompt/](http://volnitsky.com/project/git-prompt/)

\-
[http://misc.flogisoft.com/bash/tip_colors_and_formatting](http://misc.flogisoft.com/bash/tip_colors_and_formatting)

\- [http://tldp.org/LDP/abs/html/string-
manipulation.html](http://tldp.org/LDP/abs/html/string-manipulation.html)

\- [http://www.botsko.net/blog/2010/03/16/git-status-in-
command-...](http://www.botsko.net/blog/2010/03/16/git-status-in-command-
line/)

------
couchand
This is neat and I think there's a lot of potential here. As with many
information displays, though, it's critical to consider what the most
important information to convey is and how to effectively do it.

My main question is around the use of color. I'd argue the error states -
conflicts, diverging branches, etc - should be the ones in red, since those
are the issues you want to call the most attention to.

Getting rid of any chartjunk is the other big thing. Using four characters of
every prompt just for `git:` is not reasonable. And as much as I like the idea
of being warned about untracked files, I fear that in most real situations you
end up with random scratch files in the same directory. My prompt would always
say `7A` at the end, wasting more space (and mental effort!).

Good work!

~~~
michaelallen
Thanks! Glad you like it.

Fair point on the `git:(`, it's mostly a hold over from robbyrussells oh-my-
zsh theme (which inspired me to make the first version of this about 2 years
ago ([https://github.com/michaeldfallen/oh-my-
zsh/blob/master/them...](https://github.com/michaeldfallen/oh-my-
zsh/blob/master/themes/michaeldfallen.zsh-theme\))).

The entire thing is composable so if you want a prompt without those bits just
fork and modify: [https://github.com/michaeldfallen/git-
radar/blob/master/prom...](https://github.com/michaeldfallen/git-
radar/blob/master/prompt.zsh).

Or should I be making these "pieces" like `git:(` and `)` configurable through
args / env vars?

On the untracked files I personally never leave a file untracked. I either
commit it or add it to .gitignore. Though I see how you use git differently,
how about a --ignore-untracked to ignore untracked files?

~~~
ixtli
This is good stuff: I've already added it to my dotfiles git repo that sync
between machines I use. I would like, however, an option to turn off the
'git:' bit. Chartjunk is exactly what it is :)

~~~
michaelallen
Will do. I'll add the ability to change the prefix/suffix.

------
avar
Consider sending these changes upstream to contrib/completion/git-prompt.sh in
git.git. It already has a lot of toggles for adjusting the prompt. These
things you've added could be added as options.

------
Walkman
If you like this, I recommend oh-my-zsh [1] or prezto[2], both have themes for
things like this.

[1]: [https://github.com/robbyrussell/oh-my-
zsh](https://github.com/robbyrussell/oh-my-zsh)

[2]: [https://github.com/sorin-ionescu/prezto](https://github.com/sorin-
ionescu/prezto)

~~~
Shebanator
I personally use the agnoster theme from oh-my-zsh. With the required
powerline-patched font, its very readable and has enough git info to keep me
informed without taking up too much space:

[https://gist.github.com/agnoster/3712874](https://gist.github.com/agnoster/3712874)

------
JoshTriplett
I like the appearance of prompts like this, and I've tried them a few times,
but I always find myself turning them back off the first time I cd into a
large git repository and have to wait a full second or two for the prompt to
return. git is fast, but the prompt needs to show up _instantly_ , and git
isn't instantaneous on repositories the size of Linux or Chrome.

~~~
anishathalye
Have you thought about using an asynchronously rendered prompt?

~~~
JoshTriplett
That sounds disconcerting and distracting; I don't want my prompt to change
while I'm typing a command. If I already have a command prompt, I can type
"git status" easily enough.

Also, how would that work?

~~~
anishathalye
It's not that bad actually - I've been using one since February. Here's a demo
(+ code): [http://www.anishathalye.com/2015/02/07/an-asynchronous-
shell...](http://www.anishathalye.com/2015/02/07/an-asynchronous-shell-
prompt/)

~~~
JoshTriplett
Ah, I see. Interesting zsh magic, and the right-prompt mechanism makes it more
palatable. Two issues, though. First, I use bash. Second, and more
importantly, you're using the same temporary file for all shells, so the
prompts from different shells (in different working directories) will
overwrite each other.

~~~
anishathalye
Yeah, not sure if/how to do this in bash :P

Yeah, I thought about using a different temp file per shell, and I did use
that for some time, but that got annoying when shells didn't exit gracefully
and clean up the temp file.

I don't actually care about race conditions (okay, the wrong prompt may be
displayed once, big deal), and it doesn't actually happen in real use because
of the way timing works out.

------
opsunit
liquidprompt
[https://github.com/nojhan/liquidprompt](https://github.com/nojhan/liquidprompt)
is another viable alternative.

------
mallamanis
I use [https://github.com/magicmonty/bash-git-
prompt](https://github.com/magicmonty/bash-git-prompt) which I also like. It
seems to present less information than this one though

~~~
noir_lord
I use this one as well and it's great, mostly for that "did I remember to
commit and push before I go home" check.

------
lorenzfx
I use zsh-vcs-prompt [0], which also supports hg and svn.

[0] [https://github.com/yonchu/zsh-vcs-prompt](https://github.com/yonchu/zsh-
vcs-prompt)

------
oalders
I use oh-my-git for a similar purpose. [https://github.com/arialdomartini/oh-
my-git](https://github.com/arialdomartini/oh-my-git) Took some wrangling to
get the fonts to work, but I find it to be quite helpful. The README is
especially nice.

~~~
chmike
Wouldn't custom fonts lead to a problem when using ssh ?

~~~
oalders
I just got the fonts working in iTerm2 and after that I didn't have any issues
that I recall.

------
noalt
[https://github.com/dahlbyk/posh-git](https://github.com/dahlbyk/posh-git) has
had something similar for awhile - very useful!

~~~
devrelm
Push Git is great! I've been looking for a comparable solution for *nix for a
while. Zsh's git completion/prompt just showing the branch and dirty state
isn't enough.

------
laumars
You could negate the need for a --bash or --zsh flag by checking $SHELL:

    
    
      echo $SHELL | egrep -o '[a-z]+$'
    

It might also make sense to bundle everything under one file as well. While
I'd normally advocate separating code into smaller and more manageable files,
a single file shell script would be more convenient to install and would
require less disk reads per every prompt call.

Looks good though. I'm definitely going to use this on my dev boxes.

~~~
michaelallen
I did try that on a previous tool Butler
([https://github.com/michaeldfallen/butler](https://github.com/michaeldfallen/butler))
but I found that some shells don't actually set `$SHELL`.

~~~
laumars
Some don't, but $SHELL is generally accurate enough for Bash and Zsh.

You can also check the shell by checking the PID:

    
    
      ps -p $$
    

But then you need to do extra output parsing plus, obviously, _ps_ each time
you output $PS1. Which is going to be a little overkill for this project since
it's only Zsh and Bash you're wanting to capture and you can always have
fallback support for those flags when automatic detection fails.

------
zerolinesofcode
You could have called it GitHud ;-)

~~~
zvikara
Already taken:
[https://github.com/kristjan/githud](https://github.com/kristjan/githud)

~~~
nathancahill
By a 3 year old project with 5 stars..

------
leni536
I use something similar for my bash prompt:

[https://github.com/xtrementl/dev-bash-git-
ps1](https://github.com/xtrementl/dev-bash-git-ps1)

I wonder if this one is any faster. Waiting for a bash prompt in large repos
can be frustrating.

~~~
brandonwamboldt
I added logic to mine to check for a .noprompt file and disable the git part
of my bash prompt as I generally want it enabled, but a few large repos are
too slow with it. You could do something similar, I'm sure.

~~~
leni536
I wonder if an asynchronous approach could be implemented. Like starting the
git status and the likes in a separate process and killing it after a certain
timeout if it takes too long.

While I like that there is a .noprompt feature it's mainly a workaround. Maybe
there could be a toggle feature where the user can turn on and off the git
prompt on demand, wouldn't be hard to implement.

Maybe I will start hacking on it, I have some ideas to optimize it further.

~~~
anishathalye
It can be done, and it actually works quite well. See this post for a demo +
code: [http://www.anishathalye.com/2015/02/07/an-asynchronous-
shell...](http://www.anishathalye.com/2015/02/07/an-asynchronous-shell-
prompt/)

~~~
leni536
Well this is awesome, thanks for the link.

------
r3bl
Looks very promising! Thanks, we really missed something like this in Git.

~~~
TsiCClawOfLight
I find the ZSH git extension to work very well.

~~~
devrelm
Is that configurable? That is to say, can I change what's printed to the
prompt to add more info like # of files added/removed/modified? I looked into
it a little bit it looked hard-coded.

~~~
lorenzhs
yeah it's pretty configurable, the syntax to do so is rather ugly though. I'm
using it like this:
[https://gist.github.com/lorenzhs/c8b442ce831f0211f3d8](https://gist.github.com/lorenzhs/c8b442ce831f0211f3d8)
which shows me whether I have staged and unstaged changes, the current branch
and commit, rebase/... status, etc.

I don't remember from where I got this config, it's a mix of things I found
online.

~~~
devrelm
Interesting, thanks!

------
toddchambery
Anybody have a translation for the fish shell prompt?

~~~
pwenzel
Check out the "bash-git-prompt" project, which includes this fish prompt:
[https://github.com/magicmonty/bash-git-
prompt/blob/master/gi...](https://github.com/magicmonty/bash-git-
prompt/blob/master/gitprompt.fish)

------
WorldWideWayne
This is okay, but I wish OS X had something as nice as TortoiseGit.

