[PATCH b4] shell: copy zshenv and zprofile if it is zsh

Tan Siewert <[email protected]>
Newsgroups org.kernel.linux.tools
Message-ID <[email protected]>
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 <[email protected]>
---
 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 <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.