Prefix asynchronous VCS worker in prompt theme, add cleanup

This commit is contained in:
tastytea 2022-04-24 17:53:17 +02:00
parent ed72ab94d6
commit 9f4043a852
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM

View File

@ -68,10 +68,11 @@ function prompt_tastytea_vcs() {
function prompt_tastytea_vcs_async() {
# From https://vincent.bernat.ch/en/blog/2019-zsh-async-vcs-info
function prompt_tastytea_vcs_async_start() {
async_start_worker vcs_info
async_register_callback vcs_info prompt_tastytea_vcs_info_done
async_start_worker prompt_tastytea_vcs_info
async_register_callback prompt_tastytea_vcs_info \
prompt_tastytea_vcs_info_done
}
function prompt_tastytea_vcs_info() {
function prompt_tastytea_vcs_info_job() {
cd -q ${1}
vcs_info
print "${vcs_info_msg_0_}"
@ -97,8 +98,8 @@ function prompt_tastytea_vcs_async() {
vcs_info_msg_0_="${vcs_info_msg_0_//\%F\{${prompt_tastytea_colours[highlight]}/%F{${prompt_tastytea_colours[inactive]}}"
}
function prompt_tastytea_vcs_precmd() {
async_flush_jobs vcs_info
async_job vcs_info prompt_tastytea_vcs_info $PWD
async_flush_jobs prompt_tastytea_vcs_info
async_job prompt_tastytea_vcs_info prompt_tastytea_vcs_info_job $PWD
}
prompt_tastytea_vcs_async_start
@ -147,7 +148,14 @@ function prompt_tastytea_setup() {
PS4='%F{${prompt_tastytea_colours[prompt]}}+%N:%i>%f '
}
function prompt_tastytea_cleanup() {
if [[ -v ASYNC_VERSION ]]; then
async_stop_worker prompt_tastytea_vcs_info
fi
}
prompt_tastytea_setup "$@"
prompt_cleanup 'prompt_tastytea_cleanup'
# Local Variables:
# mode: shell-script