From abdd22288fe0322029fa43c35b051fb7d51d2fa7 Mon Sep 17 00:00:00 2001 From: Bodaniel Jeanes Date: Sun, 27 Jun 2010 23:53:00 +1000 Subject: [PATCH] Upgraded vcprompt to fix the empty-git-repo issue causing stderr output in the prompt --- misc/vcprompt.py | 36 ++++++++++++++++-------------------- zsh/theme | 2 +- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/misc/vcprompt.py b/misc/vcprompt.py index 277fe22..bb21006 100755 --- a/misc/vcprompt.py +++ b/misc/vcprompt.py @@ -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() \ No newline at end of file diff --git a/zsh/theme b/zsh/theme index de0145e..a00ef3c 100644 --- a/zsh/theme +++ b/zsh/theme @@ -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})'