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

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}"
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})'