Skip to content

Commit

Permalink
plugins/gx: init
Browse files Browse the repository at this point in the history
Strip `lib` from `lib.types.`

Co-authored-by: Gaétan Lepage <[email protected]>

Fix settingsExample expression

Co-authored-by: Matt Sturgeon <[email protected]>

Use '-version of options for better examples

Fix indentation in example lua code

Remove trailing space

Replace use of literalLua with strings

Revert to use literalLua

Use lib.mkDefault

Co-authored-by: Gaétan Lepage <[email protected]>
  • Loading branch information
2 people authored and nix-infra-bot committed Jan 24, 2025
1 parent 683e5ea commit 16f92ff
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 0 deletions.
122 changes: 122 additions & 0 deletions plugins/by-name/gx/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{ lib, ... }:
let
inherit (lib.nixvim) defaultNullOpts;
inherit (lib) types;
in
lib.nixvim.plugins.mkNeovimPlugin {
name = "gx";
packPathName = "gx.nvim";
package = "gx-nvim";
description = ''
Implementation of gx without the need of netrw.
'';

maintainers = [ lib.maintainers.jolars ];

extraOptions = {
disableNetrwGx = lib.mkOption {
default = true;
description = "Disable the `gx` mapping in netrw.";
type = types.bool;
};
};

extraConfig = cfg: {
globals = lib.mkIf cfg.disableNetrwGx {
netrw_nogx = lib.mkDefault true;
};
};

settingsOptions = {
open_browser_app = defaultNullOpts.mkStr null ''
Specify your browser app; default for macOS is `"open"`, Linux `"xdg-open"`
and Windows `"powershell.exe"`.
'';

open_browser_args = defaultNullOpts.mkListOf types.str [ ] ''
Arguments provided to the browser app, such as `--background` for macOS's `open`.
'';

handlers = defaultNullOpts.mkAttrsOf types.anything { } ''
Enable built-in handlers and configure custom ones. By default, all
handlers are disabled. To enable a built-in handler, set it to `true`.
'';

handler_options = {
search_engine = defaultNullOpts.mkStr "google" ''
Search engine to use when searching for text. Built-in options are
`"google"`, `"duckduckgo"`, `"ecosia"`, `"yandex"`, and `"bing"`. You
can also pass a custom search engine, such as
`"https://search.brave.com/search?q="`.
'';

select_for_search = defaultNullOpts.mkBool false ''
If your cursor is e.g. on a link, the pattern for the link AND for the word
will always match. This disables this behaviour for default so that the link is
opened without the select option for the word AND link.
'';

git_remotes = defaultNullOpts.mkListOf' {
type = types.str;
pluginDefault = [
"upstream"
"origin"
];
description = ''
List of git remotes to search for git issue linking, in priority.
You can also pass a function.
'';
example = lib.nixvim.literalLua ''
function(fname)
if fname:match("myproject") then
return { "mygit" }
end
return { "upstream", "origin" }
end
'';
};

git_remote_push = defaultNullOpts.mkBool' {
type = types.bool;
pluginDefault = false;
description = ''
Whether to use the push url for git issue linking.
You can also pass a function.
'';
example = lib.nixvim.literalLua ''
function(fname)
return fname:match("myproject")
end
'';
};
};
};

settingsExample = lib.literalExpression ''
{
open_browser_args = [ "--background" ];
handlers = {
rust = {
name = "rust";
filetype = [ "toml" ];
filename = "Cargo.toml";
handle.__raw = '''
function(mode, line, _)
local crate = require("gx.helper").find(line, mode, "(%w+)%s-=%s")
if crate then
return "https://crates.io/crates/" .. crate
end
end
''';
};
};
handler_options = {
search_engine = "duckduckgo";
git_remotes = [
"origin"
];
};
};
'';
}
64 changes: 64 additions & 0 deletions tests/test-sources/plugins/by-name/gx/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
empty = {
plugins.gx.enable = true;
};

default = {
plugins.gx = {
enable = true;

disableNetrwGx = true;

settings = {
open_browser_app = null;
open_browser_args = [ ];
handlers = { };
handler_options = {
search_engine = "google";
select_for_search = false;
git_remotes = [
"upstream"
"origin"
];
git_remote_push = false;
};
};
};
};

example = {
plugins.gx = {
enable = true;

settings = {
handlers = {
rust = {
name = "rust";
filetype = [ "toml" ];
filename = "Cargo.toml";
handle.__raw = ''
function(mode, line, _)
local crate = require("gx.helper").find(line, mode, "(%w+)%s-=%s")
if crate then
return "https://crates.io/crates/" .. crate
end
end
'';
};
};
handler_options = {
search_engine = "duckduckgo";
git_remotes.__raw = ''
function(fname)
if fname:match("myproject") then
return { "mygit" }
end
return { "upstream", "origin" }
end
'';
};
};
};
};
}

0 comments on commit 16f92ff

Please sign in to comment.