Upgraded vcprompt to fix the empty-git-repo issue causing stderr output in the prompt

pull/2/head
Bodaniel Jeanes 2010-06-27 23:53:00 +10:00
parent 29225e7f9b
commit abdd22288f
2 changed files with 17 additions and 21 deletions

View File

@ -521,6 +521,7 @@ def git(path, string, unknown):
# hash/revision # hash/revision
if re.search('%(r|h)', string) and branch != unknown: if re.search('%(r|h)', string) and branch != unknown:
hash_file = os.path.join(file, 'refs/heads/%s' % branch) hash_file = os.path.join(file, 'refs/heads/%s' % branch)
if os.path.exists(hash_file):
with open(hash_file, 'r') as f: with open(hash_file, 'r') as f:
for line in f: for line in f:
hash = line.strip()[0:7] hash = line.strip()[0:7]
@ -528,27 +529,22 @@ def git(path, string, unknown):
# status # status
if '%i' in string: if '%i' in string:
command = 'git status' command = 'git status --short -z'
process = Popen(command.split(), stdout=PIPE, stderr=PIPE) process = Popen(command.split(), stdout=PIPE, stderr=PIPE)
output = process.communicate()[0] output = process.communicate()[0]
returncode = process.returncode returncode = process.returncode
if not returncode: if not returncode:
headers = {'modified': 'M', status = 'clean'
'removed': 'D', status_codes = []
'renamed': 'R',
'Untracked': '?'}
status = ''
for line in output.split('\n'): for line in output.split('\n'):
# strip the hashes from the lines line = line.strip()
line = line[1:].strip() if not line:
# ignore informational and blank lines continue
if line and not line.startswith('('): status_codes.append(line.split()[0])
for key in headers.keys():
if line.startswith(key): if status_codes:
status += headers[key] status = sorted_alpha(status_codes)
break
status = sorted_alpha(status)
# formatting # formatting
string = string.replace('%b', branch) string = string.replace('%b', branch)

View File

@ -16,4 +16,4 @@ ZSH_THEME_VCS_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_VCS_PROMPT_FORMAT="${ZSH_THEME_VCS_PROMPT_PREFIX}%b:%h${ZSH_THEME_VCS_PROMPT_SUFFIX}" ZSH_THEME_VCS_PROMPT_FORMAT="${ZSH_THEME_VCS_PROMPT_PREFIX}%b:%h${ZSH_THEME_VCS_PROMPT_SUFFIX}"
PS1='%{$fg[blue]%}$(prompt_pwd)%{$reset_color%} %{$fg[$(prompt_color)]%}♪%{$reset_color%} ' PS1='%{$fg[blue]%}$(prompt_pwd)%{$reset_color%} %{$fg[$(prompt_color)]%}♪%{$reset_color%} '
RPS1='$(${VCPROMPT} -f ${ZSH_THEME_VCS_PROMPT_FORMAT} 2>/dev/null)' RPS1='$(${VCPROMPT} -f ${ZSH_THEME_VCS_PROMPT_FORMAT})'