Remove use of RPS1

Following on from the previous commit, use of `RPS1` results in the
prompt being redrawn when the terminal gets narrower, this makes the
line drawn by `fresh_line_one` scroll off the screen. By removing any
use of `RPS1` this behaviour goes away.
This commit is contained in:
Kenneth Benzie 2018-08-30 21:57:18 +01:00
parent df819f58a8
commit f24253b8c1

View File

@ -19,8 +19,8 @@ prompt_fresh_setup() {
autoload -U add-zsh-hook autoload -U add-zsh-hook
# Hook to print the first line of the "two line" prompt, this line is not # Hook to print the first line of the "two line" prompt, this line is not
# actually part of the prompt so does not get redrawn which can sometimes # actually part of the prompt so does not get redrawn, this is preferable
# cause lines before the prompt to disappear. # since sometimes lines before the prompt can disappear.
add-zsh-hook precmd fresh_line_one add-zsh-hook precmd fresh_line_one
if [ $almostontop -eq 1 ]; then if [ $almostontop -eq 1 ]; then
@ -46,8 +46,6 @@ prompt_fresh_setup() {
PS1="«$user» " PS1="«$user» "
PS2="«${(l:${#userhost}:: :)}» " PS2="«${(l:${#userhost}:: :)}» "
RPS1='$(fresh_rprompt)'
prompt_opts=(percent sp subst) prompt_opts=(percent sp subst)
} }
@ -89,7 +87,7 @@ fresh_line_one() {
fi fi
# Construct the git prompt # Construct the git prompt
local git="%{%F{66}%}$branch%{%f%}$ahead$behind " local git=" %{%F{66}%}$branch%{%f%}$ahead$behind "
if [ -f ~/.cache/zsh/git-prompt ]; then if [ -f ~/.cache/zsh/git-prompt ]; then
# Get the change counts from git-prompt # Get the change counts from git-prompt
@ -119,26 +117,23 @@ fresh_line_one() {
fi fi
fi fi
# Print the first line of the prompt # If the last command failed, display its error code at the right
if [[ $exit_code -ne 0 ]]; then if [[ $exit_code -ne 0 ]]; then
# The last command failed, display its error code at the right
local result=" %{%B%F{1}%}$exit_code%{%f%b%}" local result=" %{%B%F{1}%}$exit_code%{%f%b%}"
fi fi
# Construct the prompt string # If a virtualenv is enabled, display it's basename
local line="$time_stamp $directory $git$result"
print -P "$line"
}
fresh_rprompt() {
rprompt=""
if [[ ! -z "$DOCKER_MACHINE_NAME" ]]; then
rprompt="$rprompt %{%F{3}%}$DOCKER_MACHINE_NAME%{%f%}"
fi
if [[ ! -z "$VIRTUAL_ENV" ]]; then if [[ ! -z "$VIRTUAL_ENV" ]]; then
rprompt="$rprompt %{%F{3}%}$(basename $VIRTUAL_ENV)%{%f%}" py=" %{%F{4}%}py%{%f%}%{%F{3}%}$(basename $VIRTUAL_ENV)%{%f%}"
fi fi
echo $rprompt
# If docker-machine env is active, display the machines name
if [[ ! -z "$DOCKER_MACHINE_NAME" ]]; then
docker=" %{%F{6}%}$DOCKER_MACHINE_NAME%{%f%}"
fi
# Print the first line of the prompt
print -P "$time_stamp $directory$git$py$docker$result"
} }
fresh_almostontop() { fresh_almostontop() {
@ -148,10 +143,9 @@ fresh_almostontop() {
} }
fresh_compile_git_prompt() { fresh_compile_git_prompt() {
# Compile a simple C executable which parses the output of `git status # Compile a simple C program which parses the output of `git status
# --procelain` to greatly decrease the time taken to render the prompt # --procelain` to greatly decrease the time taken to draw the prompt
local cache=~/.cache/zsh local cache=~/.cache/zsh; [ ! -d $cache ] && mkdir -p $cache
if [ ! -d $cache ]; then mkdir -p $cache; fi
if [ ! -f $cache/git-prompt ]; then if [ ! -f $cache/git-prompt ]; then
cc -x c -std=gnu99 -O3 -DNDEBUG -o $cache/git-prompt - 2> /dev/null << EOF cc -x c -std=gnu99 -O3 -DNDEBUG -o $cache/git-prompt - 2> /dev/null << EOF
#include <stdio.h> #include <stdio.h>