Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add ZSH_THEME_GIT_PROMPT_UNTRACKED #863

Closed
wants to merge 1 commit into from

3 participants

@Soares

Add the ability for zsh themes to differentiate between untracked files and a simply dirty repository.

Coppied from (Steve Losh's)[https://github.com/sjl/oh-my-zsh/] fork.
He didn't seem to be making a pull request, so here's one.

@Soares Soares Tweaks to lib/git.zsh to include untracked flag
Coppied from (Steve Losh's)[https://github.com/sjl/oh-my-zsh/] fork.
He didn't seem to be making a pull request, so here's one.
b67393c
@scialex

you might want to try rewriting this using the --porcelain option. it is designed to be used in scripts and is guaranteed to be stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 25, 2012
  1. @Soares

    Tweaks to lib/git.zsh to include untracked flag

    Soares authored
    Coppied from (Steve Losh's)[https://github.com/sjl/oh-my-zsh/] fork.
    He didn't seem to be making a pull request, so here's one.
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 6 deletions.
  1. +22 −6 lib/git.zsh
View
28 lib/git.zsh
@@ -4,12 +4,19 @@ function git_prompt_info() {
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
-# Checks if working tree is dirty
-parse_git_dirty() {
- if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then
- echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
- else
- echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
+parse_git_dirty () {
+ gitstat=$(git status 2>/dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)')
+
+ if [[ $(echo ${gitstat} | grep -c "^\(# Untracked files:\|# Changed but not updated:\|# Changes not staged for commit:\)$") > 0 ]]; then
+ echo -n "$ZSH_THEME_GIT_PROMPT_UNTRACKED"
+ fi
+
+ if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then
+ echo -n "$ZSH_THEME_GIT_PROMPT_DIRTY"
+ fi
+
+ if [[ $(echo ${gitstat} | grep -v '^$' | wc -l | tr -d ' ') == 0 ]]; then
+ echo -n "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
}
@@ -20,6 +27,15 @@ function git_prompt_ahead() {
fi
}
+#
+# Will return the current branch name
+# Usage example: git pull origin $(current_branch)
+#
+function current_branch() {
+ ref=$(git symbolic-ref HEAD 2> /dev/null) || return
+ echo ${ref#refs/heads/}
+}
+
# Formats prompt string for current git commit short SHA
function git_prompt_short_sha() {
SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
Something went wrong with that request. Please try again.