aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2012-06-08 13:24:14 +1200
committerTom Ryder <tom@sanctum.geek.nz>2012-06-08 13:24:14 +1200
commitafb2ddccc640040a4fbab12963af7e0f823d6d63 (patch)
treec75a10acf354445b65217c18e637d0a32c8bba99 /bash
parentMore directories to add to $PATH automatically (diff)
downloaddotfiles-afb2ddccc640040a4fbab12963af7e0f823d6d63.tar.gz
dotfiles-afb2ddccc640040a4fbab12963af7e0f823d6d63.zip
Repository detection for prompt
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc27
1 files changed, 26 insertions, 1 deletions
diff --git a/bash/bashrc b/bash/bashrc
index 1f48ffc1..e94eec38 100644
--- a/bash/bashrc
+++ b/bash/bashrc
@@ -85,8 +85,33 @@ if grep --help | grep -- --exclude-dir &>/dev/null; then
done
fi
+# Function to display branch of a Git repository.
+function prompt_git {
+ BRANCH="$(git symbolic-ref HEAD 2>/dev/null)"
+ if [[ -n "$BRANCH" ]]; then
+ CHANGES=$(git status 2>/dev/null | grep '# \(Untracked\|Changes\|Changed but not updated:\)')
+ if [[ -n "$CHANGES" ]]; then
+ STATUS="!"
+ fi
+ echo -n "(git:${BRANCH##*/}${STATUS})"
+ fi
+}
+
+# Function to display branch of an SVN working copy.
+function prompt_svn {
+ URL="$(svn info 2>/dev/null | awk -F': ' '$1 == "URL" {print $2}')"
+ if [[ -n "$URL" ]]; then
+ ROOT="$(svn info 2>/dev/null | awk -F': ' '$1 == "Repository Root" {print $2}')/"
+ CHANGES="$(svn status 2>/dev/null)"
+ if [[ -n "$CHANGES" ]]; then
+ STATUS="!"
+ fi
+ echo -n "(svn:${URL/$ROOT}${STATUS})"
+ fi
+}
+
# Uncolored bits of my prompt, we'll color them if appropriate shortly.
-PS1='[\u@\h:\w]\$'
+PS1='[\u@\h:\w]$(prompt_git)$(prompt_svn)\$'
# Save some color codes based on our colour space.
if [[ $COLORS -ge 256 ]]; then