Update fresh prompt
* When a command fails, don't print the error code at the end of the first line but directly after the git stats. * Remove `cr` from `prompt_opts` since there is no longer a new line in `PS1`, combined with above, this result in no new lines being inserted when the terminal becomes narrower e.g. a horizontal tmux split. * Remove `fresh_visible_length` function and instead use the length of string variables e.g. `${#userhost}`.
This commit is contained in:
parent
c636dd078c
commit
df819f58a8
@ -31,24 +31,24 @@ prompt_fresh_setup() {
|
||||
add-zsh-hook -d preexec fresh_almostontop
|
||||
fi
|
||||
|
||||
if [ "$USERNAME" = "root" ]; then
|
||||
local user="%{%F{9}%}%n%{%f%}"
|
||||
if [ "$USER" = "root" ]; then
|
||||
local user="%{%F{1}%}%n%{%f%}"
|
||||
else
|
||||
local user="%{%F{35}%}%n%{%f%}"
|
||||
fi
|
||||
|
||||
local userhost=$USER
|
||||
if [ "$SSH_CONNECTION" != "" ]; then
|
||||
local user="%{%F{35}%}$user%{%f%}@%{%F{244}%}%M%{%f%}"
|
||||
local user="$user@%{%F{244}%}%M%{%f%}"
|
||||
local userhost="$userhost@`hostname`"
|
||||
fi
|
||||
|
||||
local length=`fresh_visible_length "$user"`
|
||||
|
||||
PS1="«$user» "
|
||||
PS2="${(l:$length + 1:: :)}» "
|
||||
PS2="«${(l:${#userhost}:: :)}» "
|
||||
|
||||
RPS1='$(fresh_rprompt)'
|
||||
|
||||
prompt_opts=(cr percent sp subst)
|
||||
prompt_opts=(percent sp subst)
|
||||
}
|
||||
|
||||
prompt_cleanup() {
|
||||
@ -119,18 +119,15 @@ fresh_line_one() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# Construct the prompt string
|
||||
local line="$time_stamp $directory $git"
|
||||
|
||||
# Print the first line of the prompt
|
||||
if [[ $exit_code -eq 0 ]]; then
|
||||
print -P "$line"
|
||||
else
|
||||
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 length=`fresh_visible_length "$line$result"`
|
||||
print -P "$line${(l:COLUMNS - $length - 1:: :)}$result"
|
||||
local result=" %{%B%F{1}%}$exit_code%{%f%b%}"
|
||||
fi
|
||||
|
||||
# Construct the prompt string
|
||||
local line="$time_stamp $directory $git$result"
|
||||
print -P "$line"
|
||||
}
|
||||
|
||||
fresh_rprompt() {
|
||||
@ -150,10 +147,6 @@ fresh_almostontop() {
|
||||
print -P "$PROMPT"'$1'
|
||||
}
|
||||
|
||||
fresh_visible_length() {
|
||||
echo $(( ${#${(S%%)1//(\%(KF1]|)\{*\}|\%[Bbkf])}} ))
|
||||
}
|
||||
|
||||
fresh_compile_git_prompt() {
|
||||
# Compile a simple C executable which parses the output of `git status
|
||||
# --procelain` to greatly decrease the time taken to render the prompt
|
||||
|
Loading…
x
Reference in New Issue
Block a user