aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-21 12:32:50 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-21 12:32:50 +1200
commitfe8389a2f5aad6bf4b6a6b003c349fe324cbf84d (patch)
treeb53d507fb89920bb7842ee877c0c1415b918dc1e
parent1b9f52a4c40272dfdad6c1ed5c999c039c60eca5 (diff)
downloaddotfiles-fe8389a2f5aad6bf4b6a6b003c349fe324cbf84d.tar.gz
dotfiles-fe8389a2f5aad6bf4b6a6b003c349fe324cbf84d.zip
Add some upstream checking to Git prompt
Also add some comments to be a bit less cryptic
-rw-r--r--README.markdown8
-rw-r--r--bash/bashrc.d/prompt.bash22
2 files changed, 23 insertions, 7 deletions
diff --git a/README.markdown b/README.markdown
index d9e2567d..e17ddb68 100644
--- a/README.markdown
+++ b/README.markdown
@@ -141,10 +141,10 @@ A terminal session with my prompt looks something like this:
It expands based on context to include these elements in this order:
-* Whether in a Git repository if applicable, and punctuation to show whether
- there are local modifications at a glance; Subversion support can also be
- enabled (I need it at work), in which case a `git:` or `svn:` prefix is
- added appropriately
+* Whether in a Git repository if applicable, and punctuation to show
+ repository status including reference to upstreams at a glance. Subversion
+ support can also be enabled (I need it at work), in which case a `git:` or
+ `svn:` prefix is added appropriately
* The number of running background jobs, if non-zero
* The exit status of the last command, if non-zero
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash
index dca34928..1e8c568d 100644
--- a/bash/bashrc.d/prompt.bash
+++ b/bash/bashrc.d/prompt.bash
@@ -127,14 +127,30 @@ prompt() {
# Collect symbols representing repository state
local state
+
+ # Upstream HEAD has commits after local HEAD; we're "behind"
+ (($(git rev-list --count 'HEAD..@{u}' 2>/dev/null) > 0)) &&
+ state=${state}\<
+
+ # Local HEAD has commits after upstream HEAD; we're "ahead"
+ (($(git rev-list --count '@{u}..HEAD' 2>/dev/null) > 0)) &&
+ state=${state}\>
+
+ # Tracked files are modified
git diff-files --quiet ||
- state=${state}!
+ state=${state}\!
+
+ # Changes are staged
git diff-index --cached --quiet HEAD ||
- state=${state}+
+ state=${state}\+
+
+ # There are some untracked and unignored files
[[ -n $(git ls-files --others --exclude-standard) ]] &&
state=${state}\?
+
+ # There are stashed changes
git rev-parse --quiet --verify refs/stash >/dev/null &&
- state=${state}^
+ state=${state}\^
# Print the status in brackets; add a git: prefix only if there
# might be another VCS prompt (because PROMPT_VCS is set)