From 1ba0af650ac575a7d35b10146d2e7a7b3b2e2ae6 Mon Sep 17 00:00:00 2001 From: Jacob Tomaw Date: Tue, 19 Nov 2019 12:47:12 -0500 Subject: Use safer append to hook function arrays (#8406) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use add-zsh-hook to add functions to hooks. That way they won't be added again when doing `source ~/.zshrc` multiple times. Co-authored-by: Marc Cornellà --- plugins/git-prompt/git-prompt.plugin.zsh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'plugins/git-prompt') diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git-prompt/git-prompt.plugin.zsh index 76ac2e62b..da674af98 100644 --- a/plugins/git-prompt/git-prompt.plugin.zsh +++ b/plugins/git-prompt/git-prompt.plugin.zsh @@ -20,9 +20,10 @@ function precmd_update_git_vars() { fi } -chpwd_functions+=(chpwd_update_git_vars) -precmd_functions+=(precmd_update_git_vars) -preexec_functions+=(preexec_update_git_vars) +autoload -U add-zsh-hook +add-zsh-hook chpwd chpwd_update_git_vars +add-zsh-hook precmd precmd_update_git_vars +add-zsh-hook preexec preexec_update_git_vars ## Function definitions -- cgit v1.2.3-70-g09d2 From e204c596ef5a1075914c5e7810ec1eba4bbe7411 Mon Sep 17 00:00:00 2001 From: lieryan Date: Sat, 21 Dec 2019 18:33:39 +1100 Subject: Rewrite gitstatus collection to be more robust (#7322) Fix the finicky parsing logic and just ask git the necessary information directly. --- plugins/git-prompt/gitstatus.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'plugins/git-prompt') diff --git a/plugins/git-prompt/gitstatus.py b/plugins/git-prompt/gitstatus.py index 390a50a6f..300365d71 100644 --- a/plugins/git-prompt/gitstatus.py +++ b/plugins/git-prompt/gitstatus.py @@ -4,26 +4,21 @@ from __future__ import print_function import os import sys import re -import shlex from subprocess import Popen, PIPE, check_output def get_tagname_or_hash(): """return tagname if exists else hash""" - cmd = 'git log -1 --format="%h%d"' - output = check_output(shlex.split(cmd)).decode('utf-8').strip() - hash_, tagname = None, None # get hash - m = re.search('\(.*\)$', output) - if m: - hash_ = output[:m.start()-1] + hash_cmd = ['git', 'rev-parse', '--short', 'HEAD'] + hash_ = check_output(hash_cmd).strip() + # get tagname - m = re.search('tag: .*[,\)]', output) - if m: - tagname = 'tags/' + output[m.start()+len('tag: '): m.end()-1] + tags_cmd = ['git', 'for-each-ref', '--points-at=HEAD', '--count=2', '--sort=-version:refname', '--format=%(refname:short)', 'refs/tags'] + tags = check_output(tags_cmd).split() - if tagname: - return tagname.replace(' ', '') + if tags: + return tags[0] + ('+' if len(tags) > 1 else '') elif hash_: return hash_ return None -- cgit v1.2.3-70-g09d2