Skip to content
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

programs.zsh.syntax-highlighting: support custom highlighting patterns #25323

Merged
merged 1 commit into from May 1, 2017
Merged

programs.zsh.syntax-highlighting: support custom highlighting patterns #25323

merged 1 commit into from May 1, 2017

Conversation

Ma27
Copy link
Member

@Ma27 Ma27 commented Apr 29, 2017

Motivation for this change

Last week I improved several parts of the ZSH module. However I didn't find enough time to implement custom pattern support for zsh-syntax-highlighting which I managed to do now.

I checked all configurations using the following command:

NIXOS_CONFIG=`pwd`/vmtest.nix nixos-rebuild -I nixpkgs=$HOME/Projects/nixpkgs/ build-vm
  • Test with proper configuration
    It works fine when using a configuration like this:
{
  # ...
  programs.zsh = {
    enable = true;

    syntax-highlighting = {
      enable = true;
      highlighters = [ "main" "pattern" ];
      patterns = [
        ["rm -rf *" "fg=white,bold,bg=red"]
        ["vim *" "fg=white"]
      ];
    };
  };
}
  • Assertion: it should break when configuring patterns, but the highlighters option doesn't contain the pattern highlighter:
{
  # ...
  programs.zsh = {
    enable = true;

    syntax-highlighting = {
      enable = true;
      highlighters = [ "main" ];
      patterns = [
        ["rm -rf *" "fg=white,bold,bg=red"]
        ["vim *" "fg=white"]
      ];
    };
  };

}
  • Assertion: it should break if a pattern contains more than two elements of type string (it seems as nix doesn't know tuples, so I had to write an assertion to ensure that only two elements are present in the list which represents one highlight pattern):
{
  # ...
  programs.zsh = {
    enable = true;

    syntax-highlighting = {
      enable = true;
      highlighters = [ "main" "pattern" ];
      patterns = [
        ["rm -rf *" "fg=white,bold,bg=red" "blub" "foo"]
      ];
    };
  };

}
Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@Ma27
Copy link
Member Author

Ma27 commented Apr 30, 2017

since only one of the linux/nix jobs fails: can someone tell whether it's related?


patterns = mkOption {
default = [];
type = types.listOf(types.listOf(types.string));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add an example here

@Ma27
Copy link
Member Author

Ma27 commented May 1, 2017

@Mic92 added example and did a fixup into the previous commit :-)

@Mic92 Mic92 merged commit 4c576fd into NixOS:master May 1, 2017
@Mic92
Copy link
Member

Mic92 commented May 1, 2017

Thanks!

@cstrahan
Copy link
Contributor

cstrahan commented May 2, 2017

This is great!

Would it, perhaps, make a bit more sense to make the option take an attr-set, though?

{
  # ...
  programs.zsh = {
    enable = true;

    syntax-highlighting = {
      enable = true;
      highlighters = [ "main" "pattern" ];
      patterns = {
        "rm -rf *" = "fg=white,bold,bg=red";
      };
    };
  };

}

Presumably, the pattern should be unique anyway.

@Ma27
Copy link
Member Author

Ma27 commented May 2, 2017 via email

@Ma27
Copy link
Member Author

Ma27 commented May 31, 2017

@cstrahan sorry for the delay, I finally managed to refactor the change: #26229

peti pushed a commit that referenced this pull request Jun 12, 2017
…n recursive lists for patterns

The idea has been described here: #25323 (comment)

(cherry picked from commit 0925f79)
ambrop72 pushed a commit to ambrop72/nixpkgs that referenced this pull request Jun 21, 2017
…n recursive lists for patterns

The idea has been described here: NixOS#25323 (comment)

(cherry picked from commit 0925f79)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants