-
-
Save olivierverdier/310361 to your computer and use it in GitHub Desktop.
DEPRECATED in favour of http://github.com/olivierverdier/zsh-git-prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update_current_git_vars.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
from subprocess import Popen, PIPE | |
output = Popen(['git','status'], stdout=PIPE).communicate()[0] | |
lines = output.splitlines() | |
import re | |
behead_re = re.compile(r"^# Your branch is (ahead of|behind) '(.*)' by (\d+) commit") | |
diverge_re = re.compile(r"^# and have (\d) and (\d) different") | |
symbols = {'ahead of': '↑', 'behind': '↓'} | |
bline = lines[0] | |
if bline.find('Not currently on any branch') != -1: | |
branch = Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0][:-1] | |
else: | |
branch = bline.split(' ')[3] | |
## if branch == 'master': | |
## branch = '♦' | |
bstatusline = lines[1] | |
match = behead_re.match(bstatusline) | |
if match: | |
branch += symbols[match.groups()[0]] | |
branch += match.groups()[2] | |
elif bstatusline.find('nothing to commit (working directory clean)') != -1: | |
branch += '⚡' | |
else: | |
div_match = diverge_re.match(lines[2]) | |
if div_match: | |
branch += "|{1}↕{0}".format(*div_match.groups()) | |
print '(%s)' % branch | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ -n "$__EXECUTED_GIT_COMMAND" ]; then | |
update_current_git_vars.sh | |
unset __EXECUTED_GIT_COMMAND | |
fi | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case "$1" in | |
git*) | |
__EXECUTED_GIT_COMMAND=1 | |
;; | |
esac | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ -n "$__CURRENT_GIT_BRANCH" ]; then | |
s="$__CURRENT_GIT_BRANCH" | |
printf " %s%s" "%{${fg[red]}%}" "$s" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unset __CURRENT_GIT_BRANCH | |
local stat="$(git status 2>/dev/null)" | |
local gitstatus="${HOME}/.zsh/gitstatus.py" | |
if [ -n "$stat" ]; then | |
__CURRENT_GIT_BRANCH=`python ${gitstatus}` | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialize colors. | |
autoload -U colors | |
colors | |
# Allow for functions in the prompt. | |
setopt PROMPT_SUBST | |
# Autoload zsh functions. | |
fpath=(~/.zsh/functions $fpath) | |
autoload -U ~/.zsh/functions/*(:t) | |
# Enable auto-execution of functions. | |
typeset -ga preexec_functions | |
typeset -ga precmd_functions | |
typeset -ga chpwd_functions | |
# Append git functions needed for prompt. | |
preexec_functions+='preexec_update_git_vars' | |
precmd_functions+='precmd_update_git_vars' | |
chpwd_functions+='chpwd_update_git_vars' | |
# Set the prompt. | |
PROMPT=$'%{${fg[cyan]}%}%B%~%b$(prompt_git_info)%{${fg[default]}%} ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment