Closed CircleCode closed 3 years ago
You can do it like this:
Modify my_git_formatter
to show less info in transient prompt:
diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh
index ed6ce82..1e123a5 100644
--- a/config/p10k-lean.zsh
+++ b/config/p10k-lean.zsh
@@ -391,6 +391,7 @@
res+="${meta}:${clean}${(V)VCS_STATUS_REMOTE_BRANCH//\%/%%}" # escape %
fi
+ if [[ $P9K_PROMPT != transient ]]; then
# ⇣42 if behind the remote.
(( VCS_STATUS_COMMITS_BEHIND )) && res+=" ${clean}⇣${VCS_STATUS_COMMITS_BEHIND}"
# ⇡42 if ahead of the remote; no leading space if also behind the remote: ⇣42⇡42.
@@ -421,6 +422,7 @@
# in the repository config. The number of staged and untracked files may also be unknown
# in this case.
(( VCS_STATUS_HAS_UNSTAGED == -1 )) && res+=" ${modified}─"
+ fi
typeset -g my_git_format=$res
}
vcs
to POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
before prompt_char
.Modify prompt hooks like this:
function p10k-on-post-prompt() {
p10k display '1|2|3/left_frame|3/left/background_jobs'=hide '3/left/vcs'=show
}
function p10k-on-pre-prompt() {
p10k display '1|2|3/left_frame|3/left/background_jobs'=show '3/left/vcs'=hide
}
once you know about the $P9K_PROMPT
, it seems so easy :-)
Thanks for the tip, it works like a charm
Side question: with this config,the vcs
segment is used twice. Is it computed twice, or is the computation done once, and only the display (with eventual variables interpolation) done twice?
Side question: with this config,the
vcs
segment is used twice. Is it computed twice, or is the computation done once, and only the display (with eventual variables interpolation) done twice?
The status of the git repository is computed only once and then formatted twice. Formatting is fast, so this is fine.
There is still a bit of a performance hit when you use two vcs
segments because Powerlevel10k has a few optimizations that it only uses when there is one vcs
segment. On my machine I see prompt slowdown of 3-4 milliseconds when I add a second vcs
segment. This is much lower than keyboard input latency, so it's virtually impossible to detect for a human.
thanks for your time, and the detailed explanations
I'd like to have my current prompt to show full VCS info, and the transient one to show only branch@sha1 part.
Here is an extract of my config:
I thought about adding something like
vcs2
in third line, and definemy_git_formatter2
with only the part I want to display. Then I could show and hide it inp10k-on-post-prompt
andfunction p10k-on-pre-prompt
The thing is I don't know how to create this vcs2 segment (I know this is implemented through gitstatus which make it heavily asynchronous, and I expect there is an easy way to achieve this)