Skip to content

Commit 1906ad8

Browse files
committed
Use %j to fetch jobs count
1 parent a77f161 commit 1906ad8

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ This prompt has been tested on numerous Linux and BSD distributions, as well as
5858
<details>
5959
<summary>Here are the latest features and updates.</summary>
6060

61+
- v3.11.1
62+
+ Bug fix: The background jobs indicator was not updating immediately when a job ended. The prompt now uses the native Zsh `%j` escape to fetch the number of background jobs. Please update your custom prompts accordingly; the examples below have all been updated.
6163
- v3.11.0
6264
+ Added a background jobs indicator (props to [@crai0](https://github.com/crai0/)).
6365
+ The `usr1` async method is used preferred whenever possible, as it reduces command lag considerably (props to [@romkatv](https://github.com/romkatv/) for sharing [his benchmarking system](https://github.com/romkatv/zsh-bench)).
@@ -814,7 +816,7 @@ Option | Default | Meaning
814816
`psvar[8]` | `%8v` | Previous command's execution time in seconds; only set if `AGKOZAK_CMD_EXEC_TIME` > 0 and if the execution time exceeded `AGKOZAK_CMD_EXEC_TIME`
815817
`psvar[9]` | `%9v` | `psvar[8]` pretty-printed as days, hours, minutes, and seconds, thus: `1d 2h 3m 4s`
816818
`psvar[10]` | `%10v` | Name of any virtual environment that has been activated
817-
`psvar[11]` | `%11v` | The number of background jobs running
819+
`psvar[11]` | `%11v` | The number of background jobs running (deprecated; please use `%j` instead)
818820

819821
<hr>
820822

agkozak-zsh-prompt.plugin.zsh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
# psvar[10] %10v Name of virtual environment
7474
#
7575
# psvar[11] %11v Number of jobs running in the
76-
# background
76+
# background (legacy; deprecated;
77+
# use %j)
7778
#
7879

7980
# EPOCHSECONDS is needed to display command execution time
@@ -910,13 +911,13 @@ prompt_agkozak_precmd() {
910911
*) _agkozak_set_git_psvars "$(_agkozak_branch_status)" ;;
911912
esac
912913

914+
# psvar[11] deprecated in favor of %j
915+
913916
# Clear background job count
914917
psvar[11]=''
915918

916-
# Optionally get the amount of jobs running in the background
917-
if (( ${AGKOZAK_SHOW_BG:-1} )); then
918-
psvar[11]=${${(%):-%j}#0}
919-
fi
919+
# Get the amount of jobs running in the background
920+
psvar[11]=${${(%):-%j}#0}
920921

921922
# Construct and display PROMPT and RPROMPT
922923
_agkozak_prompt_dirtrim -v ${AGKOZAK_PROMPT_DIRTRIM:-2}
@@ -957,7 +958,9 @@ _agkozak_prompt_strings() {
957958
if (( ${AGKOZAK_SHOW_VIRTUALENV:-1} )); then
958959
AGKOZAK[PROMPT]+='%(10V. %F{${AGKOZAK_COLORS_VIRTUALENV:-green}}${AGKOZAK_VIRTUALENV_CHARS[1]-[}%10v${AGKOZAK_VIRTUALENV_CHARS[2]-]}%f.)'
959960
fi
960-
AGKOZAK[PROMPT]+='%(1j. %F{${AGKOZAK_COLORS_BG_STRING:-magenta}}%j${AGKOZAK_BG_STRING:-j}%f.)'
961+
if (( ${AGKOZAK_SHOW_BG:-1} )); then
962+
AGKOZAK[PROMPT]+='%(1j. %F{${AGKOZAK_COLORS_BG_STRING:-magenta}}%j${AGKOZAK_BG_STRING:-j}%f.)'
963+
fi
961964
if (( ${AGKOZAK_LEFT_PROMPT_ONLY:-0} )); then
962965
AGKOZAK[PROMPT]+='%(3V.%F{${AGKOZAK_COLORS_BRANCH_STATUS:-yellow}}%3v%f.)'
963966
fi

0 commit comments

Comments
 (0)