mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-13 08:30:08 +00:00
Speedup VCS segment
Now the untracked files are detected via `git ls-files`, which is much faster than `git status`. Additionally, we flipped the default for checking submodules. They are now NOT checked by default, as most users probably do not use git submodules.
This commit is contained in:
parent
d07507c1eb
commit
44b4b66925
2 changed files with 30 additions and 11 deletions
|
@ -6,18 +6,12 @@
|
||||||
# https://github.com/bhilburn/powerlevel9k
|
# https://github.com/bhilburn/powerlevel9k
|
||||||
################################################################
|
################################################################
|
||||||
|
|
||||||
set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY true
|
set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY false
|
||||||
function +vi-git-untracked() {
|
function +vi-git-untracked() {
|
||||||
# TODO: check git >= 1.7.2 - see function git_compare_version()
|
if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "true" && "$(command git submodule foreach 'git ls-files --others --exclude-standard')" != "" ]]; then
|
||||||
local FLAGS
|
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
||||||
FLAGS=('--porcelain')
|
VCS_WORKDIR_HALF_DIRTY=true
|
||||||
|
elif [[ "$(command git ls-files --others --exclude-standard)" != "" ]]; then
|
||||||
if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "false" ]]; then
|
|
||||||
FLAGS+='--ignore-submodules=dirty'
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $(command git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \
|
|
||||||
-n $(command git status ${FLAGS} | \grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then
|
|
||||||
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
|
||||||
VCS_WORKDIR_HALF_DIRTY=true
|
VCS_WORKDIR_HALF_DIRTY=true
|
||||||
else
|
else
|
||||||
|
|
|
@ -375,4 +375,29 @@ function testShorteningCommitHashIsNotShownIfShowChangesetIsFalse() {
|
||||||
assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(build_left_prompt)"
|
assertEquals "%K{002} %F{000} master %k%F{002}%f " "$(build_left_prompt)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testDetectingUntrackedFilesInSubmodulesWork() {
|
||||||
|
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
|
||||||
|
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
|
||||||
|
local POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY="true"
|
||||||
|
unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND
|
||||||
|
|
||||||
|
mkdir ../submodule
|
||||||
|
cd ../submodule
|
||||||
|
git init 1>/dev/null
|
||||||
|
touch "i-am-tracked.txt"
|
||||||
|
git add . 1>/dev/null && git commit -m "Initial Commit" 1>/dev/null
|
||||||
|
# Create untracked file
|
||||||
|
touch "i-am-untracked.txt"
|
||||||
|
|
||||||
|
local submodulePath="${PWD}"
|
||||||
|
|
||||||
|
cd -
|
||||||
|
git submodule add "${submodulePath}" 2>/dev/null
|
||||||
|
git commit -m "Add submodule" 1>/dev/null
|
||||||
|
|
||||||
|
source ${P9K_HOME}/powerlevel9k.zsh-theme
|
||||||
|
|
||||||
|
assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"
|
||||||
|
}
|
||||||
|
|
||||||
source shunit2/shunit2
|
source shunit2/shunit2
|
Loading…
Reference in a new issue