Linux maintainer tooling and workflows
 help / color / mirror / Atom feed
From: Tan Siewert <tan.siewert@9elements.com>
To: tools@kernel.org
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
	 Tan Siewert <tan.siewert@9elements.com>
Subject: [PATCH RESEND b4] shell: copy zshenv and zprofile if it is zsh
Date: Wed, 16 Sep 2026 10:43:07 +0200	[thread overview]
Message-ID: <20260916-zshenv-v1-1-fea07ec9c2db@9elements.com> (raw)

ZDOTDIR gets overwritten to a temporary directory that has a generated
zshrc, based on the original file from ZDOTDIR.
According to zshall(1), zsh also reads .zshenv and .zprofile from ZDOTDIR
before .zshrc.

On NixOS / home-manager, a "$ZSH" variable is being set in .zshenv that
points to the script directory in the Nix store, which is then being
used by .zshrc. As the previous mentioned files are not being copied,
the shell is broken:

    ---
    You are now in shell mode. You can execute git commands or run checks.
    Cosmetic commit edits (reword subjects, fix trailers) are fine;
    b4 will reconcile tracking data when you return.
    Do NOT add, remove, squash, or reorder commits.
    When done, Ctrl-d to return to review UI.
    ---
    /home/sinuscosinustan/.zshrc:source:26: no such file or directory:
    /oh-my-zsh.sh
    (b4) ->  linux $(git_prompt_info)

Copy .zshenv as well as .zprofile into the temporary ZDOTDIR if they
exist to avoid a broeken shell.

Signed-off-by: Tan Siewert <tan.siewert@9elements.com>
---
 src/b4/__init__.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index d140757..c71564b 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -6339,6 +6339,13 @@ def _suspend_to_shell(
     elif shellname == 'zsh':
         real_zdotdir = os.environ.get('ZDOTDIR', os.path.expanduser('~'))
         with tempfile.TemporaryDirectory(prefix='b4-shell-') as tmpdir:
+            for zdotfile in ['.zshenv', '.zprofile']:
+                try:
+                    zfile = os.path.join(real_zdotdir, zdotfile)
+                    shutil.copy(zfile, tmpdir)
+                except FileNotFoundError:
+                    logger.debug('%s not found, ignoring', zdotfile)
+
             zshrc = os.path.join(tmpdir, '.zshrc')
             with open(zshrc, 'w') as f:
                 f.write(f'ZDOTDIR="{real_zdotdir}"\n')

---
base-commit: 1f2f768cfa57721bbc235451dbf0a777b876945f
change-id: 20260819-zshenv-c80b5520e48b

Best regards,
--
Tan Siewert <tan.siewert@9elements.com>
-- 
Tan Siewert <tan.siewert@9elements.com>


                 reply	other threads:[~2026-09-16  8:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916-zshenv-v1-1-fea07ec9c2db@9elements.com \
    --to=tan.siewert@9elements.com \
    --cc=konstantin@linuxfoundation.org \
    --cc=tools@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox