GramEditor/gram
37
981
Fork
You've already forked gram
88

Preserve wrapper-injected PATH entries during shell env capture #366

Open
dnlzro wants to merge 1 commit from dnlzro/gram:preserve-process-path into main
pull from: dnlzro/gram:preserve-process-path
merge into: GramEditor:main
GramEditor:main
GramEditor:test/wgpu-on-mac
GramEditor:test-ci/failing-test-mac
GramEditor:test/failing-test-mac
GramEditor:test/build-on-22-04
GramEditor:test/wgpu-present-mode-mailbox
GramEditor:v2.1
GramEditor:test/altgr-fix-again
GramEditor:test/2.0.0-rc1
GramEditor:test/linux-build
GramEditor:test/objc2
GramEditor:v1.2.1
First-time contributor
Copy link

Background: When Gram is launched from Finder or Spotlight (no PTY attached), load_login_shell_environment() captures the user's login shell environment and sets every variable it finds, unconditionally overwriting the current environment. This is probably the correct approach for most variables, but PATH should be treated differently...

Issue: In my Nix configuration, I want to wrap the Gram binary with a script that prepends PATH with locations of additional tools (e.g., language servers). Those injected paths aren't in my global profile, so Gram discards/overwrites them.

This is a known issue for Zed as well, affecting Home Manager users (see: nix-community/home-manager#7112).

Fix: Save the current process PATH (original) before the login shell PATH (new) is captured. Then prepend any entries present in the original but not in the new PATH (avoiding duplication).

In summary:

  • Terminal launch (PTY detected): no change; load_login_shell_environment is skipped.
  • Finder/Spotlight launch (no PTY): wrapper-injected PATH entries survive the capture, and are prepended to the login shell's PATH.
**Background:** When Gram is launched from Finder or Spotlight (no PTY attached), `load_login_shell_environment()` captures the user's **login shell** environment and sets every variable it finds, unconditionally overwriting the current environment. This is probably the correct approach for most variables, but `PATH` should be treated differently... **Issue:** In my Nix configuration, I want to wrap the Gram binary with a script that prepends `PATH` with locations of additional tools (e.g., language servers). Those injected paths aren't in my global profile, so Gram discards/overwrites them. This is a known issue for Zed as well, affecting Home Manager users (see: [nix-community/home-manager#7112](https://github.com/nix-community/home-manager/issues/7112)). **Fix:** Save the current process `PATH` (original) before the login shell `PATH` (new) is captured. Then prepend any entries present in the original but not in the new `PATH` (avoiding duplication). In summary: - Terminal launch (PTY detected): no change; `load_login_shell_environment` is skipped. - Finder/Spotlight launch (no PTY): wrapper-injected `PATH` entries survive the capture, and are prepended to the login shell's `PATH`.
Owner
Copy link

Hi, and thank you for contributing to Gram! The patch looks straight-forward, but I'll have to think about how this might affect other use cases besides Nix and if it might break something.

Hi, and thank you for contributing to Gram! The patch looks straight-forward, but I'll have to think about how this might affect other use cases besides Nix and if it might break something.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u preserve-process-path:dnlzro-preserve-process-path
git switch dnlzro-preserve-process-path

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff dnlzro-preserve-process-path
git switch dnlzro-preserve-process-path
git rebase main
git switch main
git merge --ff-only dnlzro-preserve-process-path
git switch dnlzro-preserve-process-path
git rebase main
git switch main
git merge --no-ff dnlzro-preserve-process-path
git switch main
git merge --squash dnlzro-preserve-process-path
git switch main
git merge --ff-only dnlzro-preserve-process-path
git switch main
git merge dnlzro-preserve-process-path
git push origin main
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
GramEditor/gram!366
Reference in a new issue
GramEditor/gram
No description provided.
Delete branch "dnlzro/gram:preserve-process-path"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?