-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
zsh: refactor zsh configuration for better order control over .zshrc
#6479
base: master
Are you sure you want to change the base?
Conversation
b5e6cca
to
394b2d9
Compare
Add a new option called `initExtraLast` to the zsh module. This option allows users to specify shell script code that will be executed as the last step during interactive zsh shell initialization. Signed-off-by: Qiming Chu <[email protected]>
394b2d9
to
315ce87
Compare
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 getting out of hand. We would have
initExtraBeforeCompInit
initExtraLast
initExtra
. I suggest you split all the additions to zshrc with various mkOrder
so one can insert his code wherever he wants
initContents
option for custom .zshrc
content insertion
- Users can add content anywhere by using `lib.mkOrder`, `lib.mkBefore` and `lib.mkAfter` custom configurations. - Add test cases to verify the insertion of content before and after existing configurations in `.zshrc`. Signed-off-by: Qiming Chu <[email protected]>
5879b08
to
472e79e
Compare
modules/programs/zsh.nix
Outdated
@@ -616,158 +622,162 @@ in | |||
++ optional cfg.enableCompletion pkgs.nix-zsh-completions | |||
++ optional cfg.oh-my-zsh.enable cfg.oh-my-zsh.package; | |||
|
|||
home.file."${relToDotDir ".zshrc"}".text = concatStringsSep "\n" ([ | |||
programs.zsh.initContents = mkMerge [ |
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.
the introduction of initContents
is something I would like to avoid.
Can we keep home.file."${relToDotDir ".zshrc"}".text
or use initExtra instead ?
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.
In the new commit, I've modified the implementation to use initExtra
instead of introducing initContents
as you requested.
My concern is:
To maintain compatibility, we should ensure that:
- The final .zshrc content maintains the same order of components
- Any user-provided
initExtra
content still appears in the same location (Just as they used before)
I'm having a bit of a headache assigning this content order (I want to the default insertion order of initExtra
is on the same location like before), do we need to consider the compatibility of the initExtra
option? Or is this fine for now?
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.
The final .zshrc content maintains the same order of components
That would be ideal but it doesn't have to be 100% exact. The improvement you submitted solves several open issues so we can have small changes and the tradeoff would still be good.
Any user-provided initExtra content still appears in the same location (Just as they used before)
not sure what you mean. Seems like a good thing.
Or is this fine for now?
I think it is but I am not a specialist of the merging of elements in the module, I might have missed something.
thanks for taking on this huge work. I am quite looking forward to it. |
- Renamed `initContents` to `initExtra` for consistency and clarity - Updated related test files to reflect the change - Added a new test file `zshrc-contents-insert.nix` to ensure proper functionality Signed-off-by: Qiming Chu <[email protected]>
776daea
to
f1fdc33
Compare
initContents
option for custom .zshrc
content insertion.zshrc
on a quick glance it looks fine by me. I have follow up ideas but merging this first is better, it's the hardest part. diffing my ~/.zshrc with and without this just shows a few different newlines which is fine. I would like to let this cook a few days to give the opportunity for users with different zsh setups test this since it's a "dangerous" change :) |
Changed the initialization order of `zprof` from 500 to 400 in `zsh.nix` to ensure it loads before other shell initialization steps, as it benchmarks the shell initialization process. Signed-off-by: Qiming Chu <[email protected]>
This commit introduces a new test file `zshrc-contents-init-zprof.nix` to verify the initialization of `zprof` in the `.zshrc` file. The test ensures that the `.zshrc` file exists and contains the expected `zmodload zsh/zprof` command. Signed-off-by: Qiming Chu <[email protected]>
Description
zsh.nix
to usemkMerge
andmkOrder
for better control over.zshrc
content orderinglib.mkOrder
,lib.mkBefore
andlib.mkAfter
custom configurationszshrc-contents-insert.nix
,zshrc-contents-insert-before.nix
,zshrc-contents-insert-after.nix
) to verify the behavior ofinitExtra
withmkBefore
,mkAfter
, and default insertion.Checklist
Change is backwards compatible.
Code formatted with
./format
.Code tested through
nix-shell --pure tests -A run.all
or
nix build --reference-lock-file flake.lock ./tests#test-all
using Flakes.Test cases updated/added. See example.
Commit messages are formatted like
See CONTRIBUTING for more information and recent commit messages for examples.
If this PR adds a new module
Maintainer CC