1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-09 12:06:05 +01:00

flake/dev/new-plugin: add colorscheme support

This commit is contained in:
Heitor Augusto 2025-11-02 19:55:41 -03:00
parent d01e1c17e2
commit 4b8c8dbf91
No known key found for this signature in database
GPG key ID: 3EEC05B0024AF8A4

View file

@ -5,7 +5,7 @@ import os
import re import re
from argparse import ArgumentParser from argparse import ArgumentParser
# Template for default.nix # Template for default.nix (plugin)
# TODO: conditionally include parts of the template based on args # TODO: conditionally include parts of the template based on args
default_nix_template = """{{ lib, ... }}: default_nix_template = """{{ lib, ... }}:
lib.nixvim.plugins.mkNeovimPlugin {{ lib.nixvim.plugins.mkNeovimPlugin {{
@ -24,7 +24,28 @@ lib.nixvim.plugins.mkNeovimPlugin {{
}} }}
""" """
# Template for test file # Template for default.nix (colorscheme)
colorscheme_nix_template = """{{ lib, ... }}:
lib.nixvim.plugins.mkNeovimPlugin {{
name = "{name}";
moduleName = "LUA_MODULE_NAME"; # TODO replace (or remove entirely if it is the same as `name`)
package = "{package}";
isColorscheme = true;
colorscheme = "COLORSCHEME_NAME"; # TODO replace (or set to null if it has multiple colorschemes or doesn't need to set colorscheme, or remove completely if same as name)
{maintainer_todo}maintainers = [ lib.maintainers.{maintainer} ];
# TODO provide an example for the `settings` option (or remove entirely if there is no useful example)
# NOTE you can use `lib.literalExpression` or `lib.literalMD` if needed
settingsExample = {{
foo = 42;
bar.__raw = "function() print('hello') end";
}};
}}
"""
# Template for test file (plugin)
test_nix_template = """{{ test_nix_template = """{{
empty = {{ empty = {{
plugins.{name}.enable = true; plugins.{name}.enable = true;
@ -42,6 +63,27 @@ test_nix_template = """{{
}} }}
""" """
# Template for test file (colorscheme)
colorscheme_test_nix_template = """{{
empty = {{
colorscheme = "COLORSCHEME_NAME"; # TODO replace (or remove completely if doesn't need to set colorscheme)
colorschemes.{name}.enable = true;
}};
defaults = {{
colorscheme = "COLORSCHEME_NAME"; # TODO replace (or remove completely if doesn't need to set colorscheme)
colorschemes.{name} = {{
enable = true;
settings = {{
foo = 42;
bar.__raw = "function() print('hello') end";
}};
}};
}};
}}
"""
def to_kebab_case(input_string): def to_kebab_case(input_string):
""" """
@ -163,15 +205,15 @@ def find_project_root(root_identifier):
# TODO: support interactive unmanaged args # TODO: support interactive unmanaged args
def main(): def main():
""" """
Main function to generate default.nix and test files for a new plugin. Main function to generate default.nix and test files for a new plugin or colorscheme.
""" """
DEFAULT_MAINTAINER = "YOUR_NAME" DEFAULT_MAINTAINER = "YOUR_NAME"
parser = ArgumentParser( parser = ArgumentParser(
description="Generate default.nix and test files for a new plugin" description="Generate default.nix and test files for a new plugin or colorscheme"
) )
parser.add_argument( parser.add_argument(
"originalName", type=str, help="Original name of the new plugin" "originalName", type=str, help="Original name of the new plugin or colorscheme"
) )
parser.add_argument( parser.add_argument(
"--package", "--package",
@ -186,6 +228,12 @@ def main():
help="Maintainer name (from lib.maintainers)", help="Maintainer name (from lib.maintainers)",
default=DEFAULT_MAINTAINER, default=DEFAULT_MAINTAINER,
) )
parser.add_argument(
"--colorscheme",
"-c",
action="store_true",
help="Create a colorscheme instead of a plugin",
)
parser.add_argument( parser.add_argument(
"--dry-run", "--dry-run",
"-d", "-d",
@ -207,13 +255,21 @@ def main():
root_identifier = "flake.nix" root_identifier = "flake.nix"
root_dir = find_project_root(root_identifier) root_dir = find_project_root(root_identifier)
if args.colorscheme:
plugin_template = colorscheme_nix_template
test_template = colorscheme_test_nix_template
plugin_path = f"{root_dir}/colorschemes/{name}/default.nix"
test_path = f"{root_dir}/tests/test-sources/colorschemes/{name}/default.nix"
else:
plugin_template = default_nix_template
test_template = test_nix_template
plugin_path = f"{root_dir}/plugins/by-name/{name}/default.nix" plugin_path = f"{root_dir}/plugins/by-name/{name}/default.nix"
test_path = f"{root_dir}/tests/test-sources/plugins/by-name/{name}/default.nix" test_path = f"{root_dir}/tests/test-sources/plugins/by-name/{name}/default.nix"
# Create files # Create files
create_nix_file( create_nix_file(
plugin_path, plugin_path,
default_nix_template, plugin_template,
name, name,
args.originalName, args.originalName,
package, package,
@ -223,7 +279,7 @@ def main():
) )
create_test_file( create_test_file(
test_path, test_path,
test_nix_template, test_template,
name, name,
args.dry_run, args.dry_run,
) )