From aa11d28b611a0ce4e74536dcad4ea76e6ee7806a Mon Sep 17 00:00:00 2001 From: Oliver Davies <oliver@oliverdavies.uk> Date: Thu, 23 Jan 2020 23:23:37 +0000 Subject: [PATCH] Ensure that the directory is within a git repository If not, return early in `git_prompt` info. Fixes #3 --- tag-zsh/zsh/configs/prompt.zsh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tag-zsh/zsh/configs/prompt.zsh b/tag-zsh/zsh/configs/prompt.zsh index 4afe7a46..9833ab72 100644 --- a/tag-zsh/zsh/configs/prompt.zsh +++ b/tag-zsh/zsh/configs/prompt.zsh @@ -1,3 +1,11 @@ +git_is_repo() { + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == "true" ]]; then + return 1 + fi + + return 0 +} + git_current_branch() { echo $(git rev-parse --abbrev-ref HEAD) } @@ -11,6 +19,8 @@ git_repo_is_dirty() { } git_prompt_info() { + ! git_is_repo || return + current_branch=$(git_current_branch 2> /dev/null) suffix=''