Skip to content

Commit

Permalink
Use %j to fetch jobs count
Browse files Browse the repository at this point in the history
  • Loading branch information
agkozak committed Oct 17, 2021
1 parent a77f161 commit 1906ad8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ This prompt has been tested on numerous Linux and BSD distributions, as well as
<details>
<summary>Here are the latest features and updates.</summary>

- v3.11.1
+ 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.
- v3.11.0
+ Added a background jobs indicator (props to [@crai0](https://github.com/crai0/)).
+ 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)).
Expand Down Expand Up @@ -814,7 +816,7 @@ Option | Default | Meaning
`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`
`psvar[9]` | `%9v` | `psvar[8]` pretty-printed as days, hours, minutes, and seconds, thus: `1d 2h 3m 4s`
`psvar[10]` | `%10v` | Name of any virtual environment that has been activated
`psvar[11]` | `%11v` | The number of background jobs running
`psvar[11]` | `%11v` | The number of background jobs running (deprecated; please use `%j` instead)

<hr>

Expand Down
15 changes: 9 additions & 6 deletions agkozak-zsh-prompt.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
# psvar[10] %10v Name of virtual environment
#
# psvar[11] %11v Number of jobs running in the
# background
# background (legacy; deprecated;
# use %j)
#

# EPOCHSECONDS is needed to display command execution time
Expand Down Expand Up @@ -910,13 +911,13 @@ prompt_agkozak_precmd() {
*) _agkozak_set_git_psvars "$(_agkozak_branch_status)" ;;
esac

# psvar[11] deprecated in favor of %j

# Clear background job count
psvar[11]=''

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

# Construct and display PROMPT and RPROMPT
_agkozak_prompt_dirtrim -v ${AGKOZAK_PROMPT_DIRTRIM:-2}
Expand Down Expand Up @@ -957,7 +958,9 @@ _agkozak_prompt_strings() {
if (( ${AGKOZAK_SHOW_VIRTUALENV:-1} )); then
AGKOZAK[PROMPT]+='%(10V. %F{${AGKOZAK_COLORS_VIRTUALENV:-green}}${AGKOZAK_VIRTUALENV_CHARS[1]-[}%10v${AGKOZAK_VIRTUALENV_CHARS[2]-]}%f.)'
fi
AGKOZAK[PROMPT]+='%(1j. %F{${AGKOZAK_COLORS_BG_STRING:-magenta}}%j${AGKOZAK_BG_STRING:-j}%f.)'
if (( ${AGKOZAK_SHOW_BG:-1} )); then
AGKOZAK[PROMPT]+='%(1j. %F{${AGKOZAK_COLORS_BG_STRING:-magenta}}%j${AGKOZAK_BG_STRING:-j}%f.)'
fi
if (( ${AGKOZAK_LEFT_PROMPT_ONLY:-0} )); then
AGKOZAK[PROMPT]+='%(3V.%F{${AGKOZAK_COLORS_BRANCH_STATUS:-yellow}}%3v%f.)'
fi
Expand Down

0 comments on commit 1906ad8

Please sign in to comment.