mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
plugins/clipboard-image: migrate to mkneovimplugin
This commit is contained in:
parent
3aabd32181
commit
2b03933101
3 changed files with 140 additions and 141 deletions
|
@ -1,160 +1,117 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
|
||||||
let
|
let
|
||||||
cfg = config.plugins.clipboard-image;
|
inherit (lib.nixvim) defaultNullOpts;
|
||||||
|
inherit (lib) types;
|
||||||
pluginOptions = {
|
|
||||||
imgDir =
|
|
||||||
helpers.defaultNullOpts.mkNullable
|
|
||||||
(
|
|
||||||
with lib.types;
|
|
||||||
oneOf [
|
|
||||||
str
|
|
||||||
(listOf str)
|
|
||||||
rawLua
|
|
||||||
]
|
|
||||||
)
|
|
||||||
"img"
|
|
||||||
''
|
|
||||||
Dir name where the image will be pasted to.
|
|
||||||
|
|
||||||
Note: If you want to create nested dir, it is better to use table since windows and unix
|
|
||||||
have different path separator.
|
|
||||||
'';
|
|
||||||
|
|
||||||
imgDirTxt = helpers.defaultNullOpts.mkNullable (
|
|
||||||
with lib.types;
|
|
||||||
oneOf [
|
|
||||||
str
|
|
||||||
(listOf str)
|
|
||||||
rawLua
|
|
||||||
]
|
|
||||||
) "img" "Dir that will be inserted into text/buffer.";
|
|
||||||
|
|
||||||
imgName = helpers.defaultNullOpts.mkStr {
|
|
||||||
__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
|
|
||||||
} "Image's name.";
|
|
||||||
|
|
||||||
imgHandler = helpers.defaultNullOpts.mkLuaFn "function(img) end" ''
|
|
||||||
Function that will handle image after pasted.
|
|
||||||
|
|
||||||
Note: `img` is a table that contain pasted image's `{name}` and `{path}`.
|
|
||||||
'';
|
|
||||||
|
|
||||||
affix = helpers.mkNullOrStr ''
|
|
||||||
String that sandwiched the image's path.
|
|
||||||
|
|
||||||
Default:
|
|
||||||
- `default`: `"{img_path}"`
|
|
||||||
- `markdown`: `""`
|
|
||||||
|
|
||||||
Note:
|
|
||||||
Affix can be multi lines, like this:
|
|
||||||
|
|
||||||
```nix
|
|
||||||
# You can use line break escape sequence
|
|
||||||
affix = "<\n %s\n>";
|
|
||||||
```
|
|
||||||
|
|
||||||
```nix
|
|
||||||
# Or lua's double square brackets
|
|
||||||
affix.__raw = \'\'
|
|
||||||
[[<
|
|
||||||
%s
|
|
||||||
>]]
|
|
||||||
\'\'
|
|
||||||
```
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
processPluginOptions =
|
|
||||||
opts: with opts; {
|
|
||||||
img_dir = imgDir;
|
|
||||||
img_dir_txt = imgDirTxt;
|
|
||||||
img_name = imgName;
|
|
||||||
img_handler = imgHandler;
|
|
||||||
inherit affix;
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
{
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
meta.maintainers = [ maintainers.GaetanLepage ];
|
name = "clipboard-image";
|
||||||
|
packPathName = "clipboard-image.nvim";
|
||||||
|
package = "clipboard-image-nvim";
|
||||||
|
|
||||||
options.plugins.clipboard-image = lib.nixvim.plugins.neovim.extraOptionsOptions // {
|
maintainers = [ lib.maintainers.GaetanLepage ];
|
||||||
enable = mkEnableOption "clipboard-image.nvim";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "clipboard-image.nvim" {
|
description = ''
|
||||||
default = [
|
Plugin to paste images from clipboard into Neovim.
|
||||||
"vimPlugins"
|
'';
|
||||||
"clipboard-image-nvim"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
clipboardPackage = lib.mkPackageOption pkgs "clipboard privider" {
|
extraOptions = {
|
||||||
|
clipboardPackage = lib.mkPackageOption pkgs "clipboard provider" {
|
||||||
nullable = true;
|
nullable = true;
|
||||||
default = null;
|
default = null;
|
||||||
example = [ "wl-clipboard" ];
|
example = [ "wl-clipboard" ];
|
||||||
extraDescription = ''
|
extraDescription = ''
|
||||||
${"\n\n"}
|
${"\n\n"}
|
||||||
|
|
||||||
Recommended:
|
Recommended:
|
||||||
- X11: `pkgs.xclip`
|
- X11: `pkgs.xclip`
|
||||||
- Wayland: `pkgs.wl-clipboard`
|
- Wayland: `pkgs.wl-clipboard`
|
||||||
- MacOS: `pkgs.pngpaste`
|
- MacOS: `pkgs.pngpaste`
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
default = pluginOptions;
|
settingsOptions = {
|
||||||
|
default = {
|
||||||
filetypes = mkOption {
|
img_dir =
|
||||||
type =
|
defaultNullOpts.mkNullable
|
||||||
with types;
|
(types.oneOf [
|
||||||
attrsOf (submodule {
|
types.str
|
||||||
options = pluginOptions;
|
(types.listOf types.str)
|
||||||
});
|
types.rawLua
|
||||||
apply = mapAttrs (_: processPluginOptions);
|
])
|
||||||
default = { };
|
|
||||||
description = "Override certain options for specific filetypes.";
|
|
||||||
example = {
|
|
||||||
markdown = {
|
|
||||||
imgDir = [
|
|
||||||
"src"
|
|
||||||
"assets"
|
|
||||||
"img"
|
"img"
|
||||||
];
|
|
||||||
imgDirTxt = "/assets/img";
|
|
||||||
imgHandler = ''
|
|
||||||
function(img)
|
|
||||||
local script = string.format('./image_compressor.sh "%s"', img.path)
|
|
||||||
os.execute(script)
|
|
||||||
end
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
extraPackages = [ cfg.clipboardPackage ];
|
|
||||||
|
|
||||||
extraConfigLua =
|
|
||||||
let
|
|
||||||
setupOptions =
|
|
||||||
{
|
|
||||||
default = processPluginOptions cfg.default;
|
|
||||||
}
|
|
||||||
// cfg.filetypes
|
|
||||||
// cfg.extraOptions;
|
|
||||||
in
|
|
||||||
''
|
''
|
||||||
require('clipboard-image').setup(${lib.nixvim.toLuaObject setupOptions})
|
Directory name where the image will be pasted to.
|
||||||
|
|
||||||
|
> [!Note]
|
||||||
|
> If you want to create nested dir, it is better to use table since windows and unix have different path separator.
|
||||||
|
'';
|
||||||
|
|
||||||
|
img_dir_txt = defaultNullOpts.mkNullable (types.oneOf [
|
||||||
|
types.str
|
||||||
|
(types.listOf types.str)
|
||||||
|
types.rawLua
|
||||||
|
]) "img" "Directory that will be inserted into text/buffer.";
|
||||||
|
|
||||||
|
img_name = defaultNullOpts.mkStr {
|
||||||
|
__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
|
||||||
|
} "Image's name.";
|
||||||
|
|
||||||
|
img_handler = defaultNullOpts.mkLuaFn "function(img) end" ''
|
||||||
|
Function that will handle image after pasted.
|
||||||
|
|
||||||
|
> [!Note]
|
||||||
|
> `img` is a table that contain pasted image's `{name}` and `{path}`.
|
||||||
|
'';
|
||||||
|
|
||||||
|
affix = defaultNullOpts.mkStr' {
|
||||||
|
pluginDefault = lib.literalMD ''
|
||||||
|
`default`: `"{img_path}"`
|
||||||
|
`markdown`: `""`
|
||||||
|
'';
|
||||||
|
description = "String that sandwiches the image's path.";
|
||||||
|
example = lib.literalExpression ''
|
||||||
|
> [!Note]
|
||||||
|
|
||||||
|
> ```nix
|
||||||
|
> # You can use line break escape sequence
|
||||||
|
> affix = "<\n %s\n>";
|
||||||
|
> ```
|
||||||
|
|
||||||
|
> ```nix
|
||||||
|
> # Or lua's double square brackets
|
||||||
|
> affix.__raw = \'\'
|
||||||
|
> [[<
|
||||||
|
> %s
|
||||||
|
> >]]
|
||||||
|
> \'\'
|
||||||
|
> ```
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
settingsExample = {
|
||||||
|
settings = {
|
||||||
|
img_dir = "img";
|
||||||
|
img_dir_txt = "img";
|
||||||
|
img_name.__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
|
||||||
|
img_handler.__raw = "function(img) end";
|
||||||
|
affix = "";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfig = cfg: {
|
||||||
|
extraPackages = [ cfg.clipboardPackage ];
|
||||||
|
};
|
||||||
|
|
||||||
|
# TODO: Deprecated in 2025-02-01
|
||||||
|
inherit (import ./deprecations.nix { inherit lib; })
|
||||||
|
imports
|
||||||
|
deprecateExtraOptions
|
||||||
|
optionsRenamedToSettings
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
42
plugins/by-name/clipboard-image/deprecations.nix
Normal file
42
plugins/by-name/clipboard-image/deprecations.nix
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
{ lib }:
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
(lib.mkRemovedOptionModule
|
||||||
|
[
|
||||||
|
"plugins"
|
||||||
|
"clipboard-image"
|
||||||
|
"filetypes"
|
||||||
|
]
|
||||||
|
''
|
||||||
|
Please use `plugins.clipboard-image.settings` for each filetype configuration instead.
|
||||||
|
The attribute key is the name of the filetype and contains the same options as the default key.
|
||||||
|
|
||||||
|
Note that nested options will now be snake_case, as well, to match upstream plugin configuration.
|
||||||
|
''
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
deprecateExtraOptions = true;
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
[
|
||||||
|
"default"
|
||||||
|
"imgDir"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"default"
|
||||||
|
"imgDirTxt"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"default"
|
||||||
|
"imgName"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"default"
|
||||||
|
"imgHandler"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"default"
|
||||||
|
"affix"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
|
@ -12,22 +12,22 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
clipboardPackage = pkgs.wl-clipboard;
|
clipboardPackage = pkgs.wl-clipboard;
|
||||||
|
settings = {
|
||||||
default = {
|
default = {
|
||||||
imgDir = "img";
|
img_dir = "img";
|
||||||
imgDirTxt = "img";
|
img_dir_txt = "img";
|
||||||
imgName.__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
|
img_name.__raw = "function() return os.date('%Y-%m-%d-%H-%M-%S') end";
|
||||||
imgHandler = "function(img) end";
|
img_handler.__raw = "function(img) end";
|
||||||
affix = "{img_path}";
|
affix = "";
|
||||||
};
|
};
|
||||||
filetypes = {
|
|
||||||
markdown = {
|
markdown = {
|
||||||
imgDir = [
|
img_dir = [
|
||||||
"src"
|
"src"
|
||||||
"assets"
|
"assets"
|
||||||
"img"
|
"img"
|
||||||
];
|
];
|
||||||
imgDirTxt = "/assets/img";
|
img_dir_txt = "/assets/img";
|
||||||
imgHandler = ''
|
img_handler.__raw = ''
|
||||||
function(img) -- New feature from PR #22
|
function(img) -- New feature from PR #22
|
||||||
local script = string.format('./image_compressor.sh "%s"', img.path)
|
local script = string.format('./image_compressor.sh "%s"', img.path)
|
||||||
os.execute(script)
|
os.execute(script)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue