From 571c9581b1778c382681f4b83e3e16a278513473 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 14 Sep 2013 04:15:53 +0200 Subject: [PATCH] Add a git pull check --- pure.zsh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pure.zsh b/pure.zsh index 45fcebb..0a48996 100644 --- a/pure.zsh +++ b/pure.zsh @@ -41,6 +41,11 @@ prompt_pure_preexec() { printf "\e]0;$PWD:t: $2\a" } +# string length ignoring ansi escapes +prompt_pure_string_length() { + echo ${#${(S%%)1//(\%([KF1]|)\{*\}|\%[Bbkf])}} +} + prompt_pure_precmd() { # shows the full path in the title print -Pn '\e]0;%~\a' @@ -48,7 +53,18 @@ prompt_pure_precmd() { # git info vcs_info - print -P "\n%F{blue}%~%F{8}$vcs_info_msg_0_$(prompt_pure_git_dirty) $prompt_pure_username%f %F{yellow}$(prompt_pure_cmd_exec_time)%f" + local prompt_pure_preprompt='\n%F{blue}%~%F{8}$vcs_info_msg_0_`prompt_pure_git_dirty` $prompt_pure_username%f %F{yellow}`prompt_pure_cmd_exec_time`%f' + print -P $prompt_pure_preprompt + + # check async if there is anything to pull + { + # check if we're in a git repo + command git rev-parse --is-inside-work-tree &>/dev/null || return + # check check if there is anything to pull + command git fetch && (($(git rev-list --count HEAD...$(git rev-parse --abbrev-ref @{u})) > 0)) && + # some crazy ansi magic to inject the symbol into the previous line + printf "\e[A\e[`prompt_pure_string_length $prompt_pure_preprompt`C\e[90m⇣\e[0m\n\e[2C" + } &! # reset value since `preexec` isn't always triggered unset cmd_timestamp