From 7c43fb5ef1faee9030ffc2dbcd5db79e219d360e Mon Sep 17 00:00:00 2001 From: Konstantinos Koukopoulos Date: Wed, 16 Oct 2013 11:37:23 +0200 Subject: [PATCH] fix mangled prompts. closes #30 1. error message printed when no configured upstream branch 2. 256 color code used in precmd doesn't work on my terminal 3. preexec hook mangles output when the command itself contains escape sequences 4. cursor position isn't restored correctly when you have already began typing something before the async command executes --- pure.zsh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pure.zsh b/pure.zsh index 1f9174d..81fe3ce 100644 --- a/pure.zsh +++ b/pure.zsh @@ -38,7 +38,9 @@ prompt_pure_preexec() { cmd_timestamp=$(date +%s) # shows the current dir and executed command in the title when a process is active - printf "\e]0;$PWD:t: $2\a" + print -Pn "\e]0;" + echo -nE "$PWD:t: $2" + print -Pn "\a" } # string length ignoring ansi escapes @@ -62,9 +64,11 @@ prompt_pure_precmd() { command git rev-parse --is-inside-work-tree &>/dev/null && # check check if there is anything to pull command git fetch &>/dev/null && + # check if there is an upstream configured for this branch + command git rev-parse --abbrev-ref @'{u}' &>/dev/null && (( $(command git rev-list --count HEAD...@'{u}' 2>/dev/null) > 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" + print -Pn "\e[s\e[A\e[1G\e[`prompt_pure_string_length $prompt_pure_preprompt`C%F{cyan}⇣%f\e[u" } &! # reset value since `preexec` isn't always triggered