Make gh path configurable#4
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts how the Raycast extension shells out to gh so the user’s interactive zsh config is loaded (improving PATH resolution), and adds a workaround to parse gh JSON output even if shell startup prints extra lines.
Changes:
- Switches shell invocation from login-only to interactive+login when running
gh(-lc→-ilc). - Adds a stdout “JSON array extraction” step before
JSON.parseto tolerate non-JSON noise emitted by shell init files.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PanosSynetos
left a comment
There was a problem hiding this comment.
Thank @psrpinto - I tested this and it works. Although I'm not a big fan of the JSON regex, I understand why we need to do it.
If you have any other suggestion, happy to hear it otherwise, I'll go ahead and merge this in a couple of hours
|
@PanosSynetos I'm not a huge fan of that either, I was planning on taking a look after I saw copilot's comment but ran out of time yesterday. Let me take another look. |
56d91fb to
ac69505
Compare
|
I took a deeper look into what was going on, and I realized the problem is that, in my machine, So that was the root of the problem in my case, but there could be all sorts or scenarios that result in So I figured a better solution would be to not rely on it being in the PATH, and instead reference it directly. So I changed the approach to instead make the path configurable through an extension setting, defaulting to where it is typically found when installed with homebrew. This removes the need to use an interactive shell. Let me know if this makes sense. The PR description has been updated and the commits of the previous approach were dropped. |
PanosSynetos
left a comment
There was a problem hiding this comment.
Hey @psrpinto - It doesn't seem to work as expected. When I change the path in settings, it doesn't get the new path. See screencast
I have a wrong path, it initially fails, I edit the path to the correct one, and unless I reload the extension, it doesn't get the new path from settings, but gets what it initially loaded.
We can sync if you want
Monosnap.screencast.2026-05-04.10-26-41.mp4
|
Any luck with this PR @psrpinto ? |
Avoids relying on PATH resolution in the shell, which requires an interactive login shell and produces stdout noise that corrupts JSON parsing.
ac69505 to
2627ad2
Compare
2627ad2 to
31e9571
Compare
31e9571 to
6b7f529
Compare
|
@PanosSynetos Since your review, the key change is that the gh CLI Path preference is no longer the only way the extension finds gh. It now probes the filesystem: the preference first, then the standard Homebrew locations (/opt/homebrew/bin/gh, /usr/local/bin/gh), and finally bare gh. So a wrong or stale path is no longer fatal, for a standard Homebrew install, gh is found automatically without setting the preference at all. That indirectly addresses what you ran into: since most setups don't need the preference, there's usually nothing to edit-and-reload in the first place. On the reload behavior itself — where editing the preference only takes effect after a reload — I couldn't get it to update from within a running command, only after a reload. I haven't pinned down why for certain: it looks like getPreferenceValues() doesn't pick up changes within a running process, but I'm not sure whether that's expected Raycast behavior, a dev-mode quirk, or something on our side. I think know everything works. Let me know what you think. |
Resolve the gh binary by probing the filesystem for the first existing candidate: the configured ghPath preference first, then common install locations. This keeps a wrong or stale ghPath preference from stranding the user. Read the preference per fetch rather than at module load, so an edited gh CLI Path is picked up on the next launch (Raycast keeps the module warm across launches, so a top-level read would go stale).
6b7f529 to
5497308
Compare
I was getting the following error when running the extension:
Summary
ghbinary by probing the filesystem instead of relying on the shellPATH: it checks the gh CLI Path preference first (default/opt/homebrew/bin/gh), then the standard Homebrew locations (/opt/homebrew/bin/gh,/usr/local/bin/gh), and finally bareghso the shell can resolve it — using the first that works.ghlives somewhere unusual (nix/mise/asdf, etc.) can point the extension at it directly.Why
The extension previously relied on
ghbeing discoverable via the shell'sPATH. On my machine/opt/homebrew/binis only added toPATHby an oh-my-zsh plugin that runs in interactive shells, so the non-interactive shell the extension spawns couldn't findgh. Coaxing it out of an interactive login shell (-ilc) was fragile — it also let.zshrcstdout noise corrupt JSON parsing — and slower.Probing the filesystem for the binary sidesteps PATH resolution entirely: the shell stays a plain login shell (
-lc),JSON.parseworks directly on stdout, and standard installs need no configuration.Known limitation
Changing the gh CLI Path preference does not take effect until the extension is reloaded —
getPreferenceValues()appears not to pick up changes within a running process. In practice this rarely matters, since standard Homebrew installs are found automatically without setting the preference at all.Test plan
ghat a standard Homebrew location and no preference set — confirm it succeeds/usr/local/bin/ghon Intel) and confirm it worksghcannot be found at any location