mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-06-05 05:03:16 +02:00
[plugins/async-prompt] Add async-prompt plugin
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
parent
9cd3701ac0
commit
0fec78ce1f
1 changed files with 41 additions and 0 deletions
41
plugins/async-prompt/async-prompt.plugin.zsh
Normal file
41
plugins/async-prompt/async-prompt.plugin.zsh
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
# Asynchronous prompt heavily based on Anish Athalye's [0]
|
||||||
|
# [0[ https://www.anishathalye.com/2015/02/07/an-asynchronous-shell-prompt/
|
||||||
|
#
|
||||||
|
# To use in your theme, define an `rprompt` function that echoes whatever you
|
||||||
|
# want to have on the right-hand-side prompt.
|
||||||
|
#
|
||||||
|
setopt prompt_subst # enable command substition in prompt
|
||||||
|
|
||||||
|
ASYNC_PROC=0
|
||||||
|
function precmd() {
|
||||||
|
function async() {
|
||||||
|
|
||||||
|
# save to temp file
|
||||||
|
printf "%s" "$(rprompt)" > "/tmp/zsh_prompt_$$"
|
||||||
|
|
||||||
|
# signal parent
|
||||||
|
kill -s USR1 $$
|
||||||
|
}
|
||||||
|
|
||||||
|
# do not clear RPROMPT, let it persist
|
||||||
|
|
||||||
|
# kill child if necessary
|
||||||
|
if [[ "${ASYNC_PROC}" != 0 ]]; then
|
||||||
|
kill -s HUP $ASYNC_PROC >/dev/null 2>&1 || :
|
||||||
|
fi
|
||||||
|
|
||||||
|
# start background computation
|
||||||
|
async &!
|
||||||
|
ASYNC_PROC=$!
|
||||||
|
}
|
||||||
|
|
||||||
|
function TRAPUSR1() {
|
||||||
|
# read from temp file
|
||||||
|
RPROMPT="$(cat /tmp/zsh_prompt_$$)"
|
||||||
|
|
||||||
|
# reset proc number
|
||||||
|
ASYNC_PROC=0
|
||||||
|
|
||||||
|
# redisplay
|
||||||
|
zle && zle reset-prompt
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue