93bc7953c1 fix(zsh): streaming placeholder not updated when async is enabled (#7443)
* fix: streaming placeholder not updated when async is enabled

When both async and streaming are configured on ZSH, the init command
becomes 'precmd() { source <script> }', which re-sources the script on
every prompt cycle. This unconditionally reset _omp_stream_fd=-1, causing
_omp_cleanup_stream to skip closing the previous cycle's stream fd.

The stale stream's EOF handler would later call _omp_cleanup_stream using
the global _omp_stream_fd (now pointing to the new stream's fd) and kill
the new stream before it could send any updates. The placeholder never
got replaced.

Three fixes:

1. init.go: Skip async sourcing when streaming is also active. Streaming
   provides its own async update mechanism; re-sourcing on every precmd is
   not needed and conflicts with the streaming fd lifecycle.

2. omp.zsh (_omp_stream_fd init): Use \ so a
   re-source does not clobber an in-flight stream fd.

3. omp.zsh (_omp_async_handler): On EOF, close only the specific fd that
   triggered the handler instead of calling _omp_cleanup_stream. This
   prevents any stale handler from closing the current stream's fd even if
   the global variable has diverged.

Fixes #7313

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(zsh): streaming placeholder not updated when async is enabled

When both async and streaming are configured in ZSH, the omp.zsh script
is re-sourced before every prompt cycle via the async init mechanism
(precmd() { source <script> }).  Top-level variable assignments in the
re-sourced script run unconditionally, so _omp_stream_fd was reset to -1
on every prompt cycle even while a live stream was in flight.

This caused two problems:
1. _omp_cleanup_stream skipped cleanup (fd -1 < 0) before starting the
   new stream, leaking the old fd and its ZLE handler.
2. The stale EOF handler later fired, saw _omp_stream_fd pointing at the
   NEW stream, and closed it  so the placeholder was never replaced.

Fix 1: use _omp_stream_fd=\ (ZSH := modifier) so
the fd value survives a re-source, initialising to -1 only when the
variable is genuinely unset (first source at shell startup).

Fix 2: in _omp_async_handler, guard the EOF cleanup with
[[ \ -eq \ ]] so a stale handler from a previous
prompt cycle can never close the current stream's fd.

Reverts the init.go change from the previous commit  changing the
async sourcing mechanism is unnecessary and caused a regression (exit
code 127) when streaming was enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(zsh): correct misleading comment on stream fd initialization

The comment referenced := (ZSH assign-if-unset) but the code uses :-
(use-default-if-unset). Update the comment to accurately describe
what the expansion does.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-09 10:20:17 +02:00
2025-09-11 11:23:29 +02:00
2024-09-19 08:29:35 +02:00
2026-02-16 16:26:51 +01:00
2026-03-10 17:15:47 +01:00
2026-03-18 09:13:59 +01:00
2026-03-11 16:58:22 +01:00
2022-02-28 07:48:03 +01:00
2026-01-01 12:26:50 +01:00
2023-10-05 11:41:05 +02:00

Oh My Posh logo – Prompt theme engine for any shell

MIT license badge

Build Status badge

Release version number badge

Documentation link badge ohmyposh.dev

Number of GitHub Downloads badge

This repo was made with love using GitKraken.

GitKraken shield

Sponsors

Documentation link badge ohmyposh.dev

Want to become a sponsor?

Join the community

Mastodon badge

Discord badge

What started as the offspring of oh-my-posh2 for PowerShell resulted in a cross platform, highly customizable and extensible prompt theme engine. After 4 years of working on oh-my-posh, a modern and more efficient tool was needed to suit my personal needs.

❤️ Support ❤️

Swag - Show your love with a t-shirt!

GitHub - One time support, or a recurring donation?

Ko-Fi - No coffee, no code.

Features

  • Shell and platform agnostic
  • Easily configurable
  • The most configurable prompt utility
  • Fast
  • Secondary prompt
  • Right prompt
  • Transient prompt

Documentation

Documentation

Reviews

Thanks

S
Description
The most customisable and low-latency cross platform/shell prompt renderer
Readme
159 MiB
Languages
Go 66.1%
MDX 19.2%
JavaScript 9%
PowerShell 2%
Shell 1.7%
Other 1.7%