A heads up display for git
github.com
github.com
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. watch -n 2 'git status --short; git --no-pager diff --shortstat;' while :; do clear; git status --short; git --no-pager diff --shortstat; sleep 2; doneI like my git prompt to show me my branch name, colored with grey (no changes), red (unsaved changes), or green (staged changes), with the depth of the branch, e.g.:
gknoy@host:~/dev/foo/[bar-feature:4]$
My prompt is based on: https://gist.github.com/tobiassjosten/828432... but I've made slight modifications:
# I sometimes have very long branch names.
# I don't assume it's a hash:
if [ ${#GIT_BRANCH} -gt 40 ]; then
# GIT_BRANCH="(no branch)"
GIT_BRANCH="${GIT_BRANCH:0:40}..."
fi
and, at the end of `git_prompt`: branch_depth=`git rev-list HEAD --not --remotes|wc -l`
echo "[$git_color$GIT_BRANCH$c_reset:${branch_depth}]" echo "$file"
inside the while loop, what do you see?I deliberately set the .git directory to be ignored (using @) to avoid tons of repeating when the index.lock file is repeatedly recreated. Maybe that's what's going on here.
alternating very fast.
I must have fumbled a key after pasting, as there was a dot missing; @/.git should read @./.git.
I'll add a note to the ancestor comment if I still can. Thanks and sorry!
[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;"
Sorry!- Mikko Nylén's comment in http://web.archive.org/web/20130127054804/http://asemanfar.c...
- http://stackoverflow.com/questions/8120553/bash-profile-sett...
- http://volnitsky.com/project/git-prompt/
- http://misc.flogisoft.com/bash/tip_colors_and_formatting
- http://tldp.org/LDP/abs/html/string-manipulation.html
- http://www.botsko.net/blog/2010/03/16/git-status-in-command-...
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!
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...).
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....
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?
I'm totally on board with you about trying not to leave things untracked. It seems like things always accumulate that shouldn't be committed but are useful; I should probably just move them to a different root folder.
Here's the prompt I use[0], adapted from some shell script I found online somewhere. I'm not going to link to the code because it's kind of ugly but it is up on my github.
A clean repository is subdued but readable blue. When there are unstaged changes there's a red plus, and staged changes get a green plus (some of both is yellow). Any branch discrepancies at all are shown by writing the branch name in bold red.
I don't try to give myself too much information, making the assumption that you'll have to do some digging to get enough detail to actually do anything about the situation.
Also, how would that work?
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.
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.
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.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.
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.
I don't remember from where I got this config, it's a mix of things I found online.