-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
---@class dotvim | ||
local M = {} | ||
|
||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
---@class dotvim.core.plugin.ExtraPluginOptions | ||
---@field pname? string nix plugin name | ||
---@field gui? "all"|string[] Can be used in which gui environment | ||
---@field actions? dotvim.core.action.ActionOption[]|fun():dotvim.core.action.ActionOption[] | ||
|
||
---@class dotvim.core.plugin.PluginOption: dotvim.core.plugin.ExtraPluginOptions,LazyPluginSpec | ||
|
||
---@class dotvim.core.plugin.Plugin: dotvim.core.plugin.PluginOption,LazyPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
---@class dotvim.core.action | ||
local M = {} | ||
|
||
---@class dotvim.core.action.KeySpec: LazyKeysBase | ||
---@field mode? string|string[] | ||
|
||
---@alias dotvim.core.action.Condition fun(buf:dora.lib.vim.BufferWrapper):boolean | ||
|
||
---@class dotvim.core.action.ActionOption | ||
---@field id string Unique id | ||
---@field title string | ||
---@field callback string|function | ||
---@field icon? string | ||
---@field category? string | ||
---@field description? string Shown description if action hovered | ||
---@field keys? string|(string|dotvim.core.action.KeySpec)[] | ||
---@field plugin? string | ||
---@field condition? dotvim.core.action.Condition | ||
|
||
---@class dotvim.core.action.Action: dotvim.core.action.ActionOption | ||
local Action = {} | ||
|
||
function Action:execute() | ||
local callback = self.callback | ||
if type(callback) == "string" then | ||
vim.cmd(callback) | ||
else | ||
callback() | ||
end | ||
end | ||
|
||
---@return LazyKeysSpec[] | ||
function Action:into_lazy_keys_spec() | ||
local keys = self.keys | ||
if not keys then | ||
return {} | ||
end | ||
local callback = function() | ||
self:execute() | ||
end | ||
if type(keys) == "string" then | ||
return { | ||
{ | ||
keys, | ||
callback, | ||
}, | ||
} | ||
end | ||
if not vim.tbl_isarray(keys) then | ||
keys = { keys } | ||
end | ||
|
||
local res = {} | ||
for _, key in ipairs(keys) do | ||
if type(key) == "string" then | ||
res[#res + 1] = { | ||
key, | ||
callback, | ||
} | ||
else | ||
---@type dotvim.core.action.KeySpec | ||
local k = vim.deepcopy(key) | ||
k[2] = callback | ||
res[#res + 1] = k | ||
end | ||
end | ||
|
||
return res | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
---@class dotvim.utils.fn | ||
local M = {} | ||
|
||
---@generic T | ||
---@param fun fun():T | ||
---@return fun():T | ||
function M.invoke_once(fun) | ||
local res | ||
local invoked = false | ||
return function() | ||
if not invoked then | ||
res = fun() | ||
invoked = true | ||
end | ||
return res | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
---@class dotvim.utils.fs | ||
local M = {} | ||
|
||
---@param file string filename | ||
---@return string? | ||
function M.read_file(file) | ||
local fd = io.open(file, "r") | ||
if fd == nil then | ||
return nil | ||
end | ||
---@type string | ||
local data = fd:read("*a") | ||
fd:close() | ||
return data | ||
end | ||
|
||
---@param file string filename | ||
---@param contents string | ||
function M.write_file(file, contents) | ||
local fd = assert(io.open(file, "w+")) | ||
fd:write(contents) | ||
fd:close() | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
---@class dotvim.utils.nix | ||
local M = {} | ||
|
||
---@type dotvim.utils.fn | ||
local fn = require("dotvim.utils.fn") | ||
---@type dotvim.utils.fs | ||
local fs = require("dotvim.utils.fs") | ||
|
||
---@type fun():string[] | ||
local get_plugin_packages = fn.invoke_once(function() | ||
local obj = vim | ||
.system( | ||
{ "nix-store", "--query", "--requisites", "/run/current-system" }, | ||
{ text = true } | ||
) | ||
:wait() | ||
if obj.code == 0 then | ||
---@type string[] | ||
local lines = vim.split(obj.stdout or "", "\n", { trimempty = true }) | ||
local res = {} | ||
for _, value in ipairs(lines) do | ||
if value:find("vimplugin-") then | ||
res[#res + 1] = value | ||
end | ||
end | ||
return res | ||
else | ||
return {} | ||
end | ||
end) | ||
|
||
function M.update_nix_plugin_packages() | ||
local packages = get_plugin_packages() | ||
fs.write_file( | ||
vim.fn.stdpath("data") .. "/nix-plugin-packages", | ||
table.concat(packages, "\n") | ||
) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters