-
-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(layout): Support environment variables in cwd (#2288) #2291
Conversation
* add `shellexpand` as dependency * expand environment variable in kdl parser's `parse_cwd()`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I'm happy to see this! On the whole this looks good. I left one minor comment in the code, but there are some behaviours that I think we need to look more deeply into.
shellexpand
mentions that they can also handle tildes (~
) at the beginning of paths. So that we can do something like~/my/folder
that will be expanded to/home/aram/my/folder
. Could we also support those while we're here?- We need to make sure this also works and does the right thing with cwd composition in its various permutations (also to be sure that we do the right thing after addressing point 1... maybe only invoke shellexpand for the whole string?)
- Be sure we support
cwd
for bare panes (eg.pane cwd="my/folder"
), command panes (eg.pane command="ls" cwd="my/folder"
) and edit pans (eg.pane edit="my_file.rs" cwd="my/folder"
). All of these should behave properly with env variables and tildes
Thanks again for this! Looking forward to seeing this merged soon.
Hi. Thanks for the quick reply! |
* Return a proper `ConfigError` on failures. * Replace raw cwd parsing with `parse_cwd()`. * Add tests that verify correct expansions.
Hi @imsnif, |
Hey @shahamran - sorry for taking so long to get to this! Good progress! I did some manual tests and found that there are some places in which we're still not picking this up. I think this needs to work in the layouts wherever we have a path, otherwise it might be confusing. I didn't test everything, but just a few examples:
Would you like to take a look at these and maybe do another sweep of the layout file to find out if there might be other places we'll need to add this functionality to? |
I see. In this case, I think the 2 most reasonable options are:
Regarding 1, why is this a macro? couldn't it be a regular function that takes a |
I dunno, it works :) Do whatever you think is best, let me know when you'd like another review. I'll try to get to it ASAP but thank you for your patience! |
Hi, sorry for the long delay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, great work! Thanks for making all the changes. This looks to be in great shape - I left some minor comments in the code - I think once they are addressed we can merge. Looking forward to seeing this in main.
#[track_caller] | ||
fn env_test_helper(layout_str: &str, env_vars: Vec<(&str, &str)>, expected_output: Vec<&str>) { | ||
for (key, value) in &env_vars { | ||
std::env::set_var(key, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will set the environment variable globally for all the tests, no? I'm a little wary of such things. Ideally we can find a solution that does this locally only for one test, and if not maybe we can unset these after the assert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's true, and this is why I used weird names for the vars I set (besides $HOME
).
current version handles restoring the previous env after parsing.
|
||
#[test] | ||
fn env_valid_global_cwd() { | ||
env_test_helper( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, but I personally find it a little hard to understand at a glance. Which I think is important when we're considering tests. How about we change it to something like (pseudocode, if you have a better idea then by all means!)
LayoutTesterWithEnvironment::new()
.set_env_variables(/* ... */)
.parse_layout(stringified_layout)
.assert(/* .. */)
.assert(/* .. */)
); | ||
} | ||
for s in expected_output { | ||
assert!(layout.contains(s), "expected string `{s}` was not found"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about asserting the cwd in the parsed structures (iirc they are a TildPaneLayout
in this case) directly instead of parsing and stringifying? I think it'll be more accurate and clear, but maybe it's too much work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the snapshot test I added handles this request indirectly 😃
Hi, thanks for the feedback :) I agree the test helper thing was ugly and fragile. I merged the tests to a single snapshot test, and went over the generated file. I also handled adding / removing env vars in a more correct way. Let me know if this looks good to you, and feel free to request as many changes as needed! |
@imsnif ping :) |
Hey @shahamran - thank you for your patience. It's not always easy for me to get to everything that needs attention in the project in a timely manner, so I appreciate your understanding. Great work on the changes, I'm happy to go ahead and merge this. Thanks for your diligent work and perseverance! |
Thanks a lot @imsnif, for the guidance and feedback. While working on this, I noticed a place that I think can be improved, and I'm not sure opening an issue is the right place for it, so I'm asking here: |
Hey @shahamran - while I very much appreciate the offer, I think if we consider refactoring this area of the code it would be best to re-write it in the new KQL (I believe it is called) - the KDL query language. But I'm afraid even that is not in my focus right now. This project is still pre 1.0, which means most of the changes that happen are on a larger scope (eg. adding a web client). There will be lots of time for refactoring and improving the developer experience once things stabilize a bit. More info about what we're focusing on here. If you're interested in helping out in those areas, you can hop by discord and ask for specific guidance on issues in our development channel. Thanks again for your contribution! |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [aquaproj/aqua-registry](https://github.com/aquaproj/aqua-registry) | minor | `v4.19.0` -> `v4.20.0` | | [zellij-org/zellij](https://github.com/zellij-org/zellij) | minor | `v0.36.0` -> `v0.37.0` | --- ### Release Notes <details> <summary>aquaproj/aqua-registry</summary> ### [`v4.20.0`](https://github.com/aquaproj/aqua-registry/releases/tag/v4.20.0) [Compare Source](https://github.com/aquaproj/aqua-registry/compare/v4.19.0...v4.20.0) [Issues](https://github.com/aquaproj/aqua-registry/issues?q=is%3Aissue+milestone%3Av4.20.0) | [Pull Requests](https://github.com/aquaproj/aqua-registry/pulls?q=is%3Apr+milestone%3Av4.20.0) | aquaproj/aqua-registry@v4.19.0...v4.20.0 #### 🎉 New Packages [#​13132](https://github.com/aquaproj/aqua-registry/issues/13132) [segmentio/golines](https://github.com/segmentio/golines): A golang formatter that fixes long lines [@​iwata](https://github.com/iwata) #### Fixes [#​13143](https://github.com/aquaproj/aqua-registry/issues/13143) [terraform-linters/tflint](https://github.com/terraform-linters/tflint): Support old versions </details> <details> <summary>zellij-org/zellij</summary> ### [`v0.37.0`](https://github.com/zellij-org/zellij/releases/tag/v0.37.0) [Compare Source](https://github.com/zellij-org/zellij/compare/v0.36.0...v0.37.0) In this release we've done a lot of work on our WebAssembly / WASI plugin system and are very excited to invite adventurous Rust developers to come pioneer our plugin system with us. To read more, please see the official [Plugin Documentation](https://zellij.dev/documentation/plugins.html). Please also drop by our Discord or Matrix and show us the plugins you're working on! #### Other Highlights - Some basic themes are now included with the release, give it a try by starting Zellij with `zellij options --theme catppuccin-mocha` - Layouts now support environment variables and tilde expansions - We can now provide a `--cwd` option when starting Zellij #### All changes - fix(plugin): respect hide session option on compact-bar by [@​pedromfedricci](https://github.com/pedromfedricci) in [https://github.com/zellij-org/zellij/pull/2368](https://github.com/zellij-org/zellij/pull/2368) - feat: Add layout configuration to exclude panes from tab sync by [@​on3iro](https://github.com/on3iro) in [https://github.com/zellij-org/zellij/pull/2314](https://github.com/zellij-org/zellij/pull/2314) - Fix 2205 - Support cwd by [@​Kangaxx-0](https://github.com/Kangaxx-0) in [https://github.com/zellij-org/zellij/pull/2290](https://github.com/zellij-org/zellij/pull/2290) - feat(plugins): reload plugin at runtime by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2372](https://github.com/zellij-org/zellij/pull/2372) - Update architecture doc by [@​Kangaxx-0](https://github.com/Kangaxx-0) in [https://github.com/zellij-org/zellij/pull/2371](https://github.com/zellij-org/zellij/pull/2371) - feat(themes): add nightfox themes by [@​EdenEast](https://github.com/EdenEast) in [https://github.com/zellij-org/zellij/pull/2384](https://github.com/zellij-org/zellij/pull/2384) - feat: provide default themes by [@​jaeheonji](https://github.com/jaeheonji) in [https://github.com/zellij-org/zellij/pull/2307](https://github.com/zellij-org/zellij/pull/2307) - feat(plugins): update and render plugins asynchronously by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2410](https://github.com/zellij-org/zellij/pull/2410) - feat(layout): Support environment variables in cwd ([#​2288](https://github.com/zellij-org/zellij/issues/2288)) by [@​shahamran](https://github.com/shahamran) in [https://github.com/zellij-org/zellij/pull/2291](https://github.com/zellij-org/zellij/pull/2291) - Add file path context to all IO errors in ConfigError by [@​Imberflur](https://github.com/Imberflur) in [https://github.com/zellij-org/zellij/pull/2412](https://github.com/zellij-org/zellij/pull/2412) - fix(e2e): fix flaky locked mode test by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2413](https://github.com/zellij-org/zellij/pull/2413) - Fix error loading non-existant themes directory and use default themes as the base when merging by [@​Imberflur](https://github.com/Imberflur) in [https://github.com/zellij-org/zellij/pull/2411](https://github.com/zellij-org/zellij/pull/2411) - improve build/ci times by [@​tlinford](https://github.com/tlinford) in [https://github.com/zellij-org/zellij/pull/2396](https://github.com/zellij-org/zellij/pull/2396) - Do not unwrap() the sticky bit setting! by [@​valpackett](https://github.com/valpackett) in [https://github.com/zellij-org/zellij/pull/2424](https://github.com/zellij-org/zellij/pull/2424) - Use rust 1.67 by [@​har7an](https://github.com/har7an) in [https://github.com/zellij-org/zellij/pull/2375](https://github.com/zellij-org/zellij/pull/2375) - Fix issue 2421 - Update config file output by [@​Kangaxx-0](https://github.com/Kangaxx-0) in [https://github.com/zellij-org/zellij/pull/2443](https://github.com/zellij-org/zellij/pull/2443) - feat(plugins): Plugin workers and strider by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2449](https://github.com/zellij-org/zellij/pull/2449) - fix: cwd of newtab action by [@​onichandame](https://github.com/onichandame) in [https://github.com/zellij-org/zellij/pull/2455](https://github.com/zellij-org/zellij/pull/2455) - feat(wasm-plugin-system): major overhaul and some goodies by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2510](https://github.com/zellij-org/zellij/pull/2510) - feat(plugins): extensive plugin api by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2516](https://github.com/zellij-org/zellij/pull/2516) - fix: runtime panic because of local cache by [@​jaeheonji](https://github.com/jaeheonji) in [https://github.com/zellij-org/zellij/pull/2522](https://github.com/zellij-org/zellij/pull/2522) - fix(output): do not hide cursor on a render that does not include visual assets by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2528](https://github.com/zellij-org/zellij/pull/2528) - fix(screen): focus tab as well as pane when launching existing plugin by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2530](https://github.com/zellij-org/zellij/pull/2530) - fix(strider): clear search term on ESC by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2531](https://github.com/zellij-org/zellij/pull/2531) - fix(plugins): only listen to hd if a plugin is subscribed to hd events by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2529](https://github.com/zellij-org/zellij/pull/2529) - fix(logs): suppress debug logs when not debugging by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2532](https://github.com/zellij-org/zellij/pull/2532) - fix(plugins): allow loading relative urls by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2539](https://github.com/zellij-org/zellij/pull/2539) - feat(plugins): plugin pane state events by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2545](https://github.com/zellij-org/zellij/pull/2545) - performance(plugins): use a debounced fs watcher by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2546](https://github.com/zellij-org/zellij/pull/2546) - feat(plugins): more plugin api methods by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2550](https://github.com/zellij-org/zellij/pull/2550) - refactor(plugins): improve api by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2552](https://github.com/zellij-org/zellij/pull/2552) - feat(plugins): strider improvements by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2551](https://github.com/zellij-org/zellij/pull/2551) - docs(plugins): document the zellij-tile events and commands api by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2554](https://github.com/zellij-org/zellij/pull/2554) - docs(plugins): better zellij-tile-docs by [@​imsnif](https://github.com/imsnif) in [https://github.com/zellij-org/zellij/pull/2560](https://github.com/zellij-org/zellij/pull/2560) #### New Contributors - [@​on3iro](https://github.com/on3iro) made their first contribution in [https://github.com/zellij-org/zellij/pull/2314](https://github.com/zellij-org/zellij/pull/2314) - [@​Kangaxx-0](https://github.com/Kangaxx-0) made their first contribution in [https://github.com/zellij-org/zellij/pull/2290](https://github.com/zellij-org/zellij/pull/2290) - [@​EdenEast](https://github.com/EdenEast) made their first contribution in [https://github.com/zellij-org/zellij/pull/2384](https://github.com/zellij-org/zellij/pull/2384) - [@​shahamran](https://github.com/shahamran) made their first contribution in [https://github.com/zellij-org/zellij/pull/2291](https://github.com/zellij-org/zellij/pull/2291) - [@​Imberflur](https://github.com/Imberflur) made their first contribution in [https://github.com/zellij-org/zellij/pull/2412](https://github.com/zellij-org/zellij/pull/2412) - [@​valpackett](https://github.com/valpackett) made their first contribution in [https://github.com/zellij-org/zellij/pull/2424](https://github.com/zellij-org/zellij/pull/2424) - [@​onichandame](https://github.com/onichandame) made their first contribution in [https://github.com/zellij-org/zellij/pull/2455](https://github.com/zellij-org/zellij/pull/2455) **Full Changelog**: zellij-org/zellij@v0.36.0...v0.37.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/scottames/dots). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMjYuMCIsInVwZGF0ZWRJblZlciI6IjM1LjEyNi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Thanks for the great work! I just wanted to ask whether this was also supposed to fix the issue of env variables not accepted as values for options within the config file or not. The reason I'm asking is that something like Sorry if that's unrelated or if this is not the right place to raise this. |
Hi @MurtadhaInit. Can you open an issue, and I'll try to look into it? Please include steps to reproduce the problem. Thanks! |
@shahamran Hi, I've opened an issue 2574 |
Fixes #2288.
shellexpand
as dependency. I hope it's fine, it only hasdirs
as a dependency.parse_cwd()
.It's my first time creating a PR here. Tell me if I missed anything! 😃