2 Commits 130002a79e ... ec1afe9dd6

Author SHA1 Message Date
  Marc Cornellà ec1afe9dd6 feat(git)!: enable async git prompt (now for real) 4 weeks ago
  Loïc Yhuel b43b84abc7 fix(async): avoid blocking the shell while waiting (#12304) 4 weeks ago
3 changed files with 18 additions and 10 deletions
  1. 12 0
      README.md
  2. 5 9
      lib/async_prompt.zsh
  3. 1 1
      lib/git.zsh

+ 12 - 0
README.md

@@ -43,6 +43,7 @@ To learn more, visit [ohmyz.sh](https://ohmyz.sh), follow [@ohmyzsh](https://twi
   - [Custom Plugins And Themes](#custom-plugins-and-themes)
   - [Enable GNU ls In macOS And freeBSD Systems](#enable-gnu-ls-in-macos-and-freebsd-systems)
   - [Skip Aliases](#skip-aliases)
+  - [Disable async git prompt](#disable-async-git-prompt)
 - [Getting Updates](#getting-updates)
   - [Updates Verbosity](#updates-verbosity)
   - [Manual Updates](#manual-updates)
@@ -361,6 +362,17 @@ Instead, you can now use the following:
 zstyle ':omz:lib:directories' aliases no
 ```
 
+### Disable async git prompt
+
+Async prompt functions are an experimental feature (included on April 3, 2024) that allows Oh My Zsh to render prompt information
+asyncronously. This can improve prompt rendering performance, but it might not work well with some setups. We hope that's not an
+issue, but if you're seeing problems with this new feature, you can turn it of by setting the following in your .zshrc file,
+before Oh My Zsh is sourced:
+
+```sh
+zstyle ':omz:alpha:lib:git' async-prompt no
+```
+
 #### Notice <!-- omit in toc -->
 
 > This feature is currently in a testing phase and it may be subject to change in the future.

+ 5 - 9
lib/async_prompt.zsh

@@ -82,10 +82,8 @@ function _omz_async_request {
     exec {fd}< <(
       # Tell parent process our PID
       builtin echo ${sysparams[pid]}
-      # Store handler name for callback
-      builtin echo $handler
       # Set exit code for the handler if used
-      (exit $ret)
+      () { return $ret }
       # Run the async function handler
       $handler
     )
@@ -98,8 +96,7 @@ function _omz_async_request {
     command true
 
     # Save the PID from the handler child process
-    read pid <&$fd
-    _OMZ_ASYNC_PIDS[$handler]=$pid
+    read -u $fd "_OMZ_ASYNC_PIDS[$handler]"
 
     # When the fd is readable, call the response handler
     zle -F "$fd" _omz_async_callback
@@ -114,15 +111,14 @@ function _omz_async_callback() {
   local err=$2  # Second arg will be passed in case of error
 
   if [[ -z "$err" || "$err" == "hup" ]]; then
-    # Get handler name from first line
-    local handler
-    read handler <&$fd
+    # Get handler name from fd
+    local handler="${(k)_OMZ_ASYNC_FDS[(r)$fd]}"
 
     # Store old output which is supposed to be already printed
     local old_output="${_OMZ_ASYNC_OUTPUT[$handler]}"
 
     # Read output from fd
-    _OMZ_ASYNC_OUTPUT[$handler]="$(cat <&$fd)"
+    IFS= read -r -u $fd -d '' "_OMZ_ASYNC_OUTPUT[$handler]"
 
     # Repaint prompt if output has changed
     if [[ "$old_output" != "${_OMZ_ASYNC_OUTPUT[$handler]}" ]]; then

+ 1 - 1
lib/git.zsh

@@ -38,7 +38,7 @@ function _omz_git_prompt_status() {
 }
 
 # Enable async prompt by default unless the setting is at false / no
-if zstyle -t ':omz:alpha:lib:git' async-prompt; then
+if zstyle -T ':omz:alpha:lib:git' async-prompt; then
   function git_prompt_info() {
     if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]" ]]; then
       echo -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]"