Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Aug 4, 2024
1 parent e82ff18 commit 2e94730
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: panvimdoc
uses: kdheepak/panvimdoc@main
with:
vimdoc: nvim-plugin-template
vimdoc: minpm
treesitter: true
- uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand Down Expand Up @@ -61,3 +61,4 @@ jobs:
luarocks install luacheck
luarocks install vusted
vusted ./test
vusted ./test
File renamed without changes.
116 changes: 116 additions & 0 deletions lua/minpm/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
local api, stdpath, uv = vim.api, vim.fn.stdpath, vim.uv
local repos, INSTALL, UPDATE = {}, 0, 1
local data_dir = stdpath('data')
---@diagnostic disable-next-line: param-type-mismatch
local STARTDIR = vim.fs.joinpath(data_dir, 'site', 'minpm', 'start')
---@diagnostic disable-next-line: param-type-mismatch
local OPTDIR = vim.fs.joinpath(data_dir, 'site', 'minpm', 'opt')

local function as_table(data)
return type(data) ~= 'table' and { data } or data
end

local use_meta = {}
use_meta.__index = use_meta
function use_meta:event(e)
self.event = as_table(e)
self.islazy = true
return self
end

function use_meta:ft(ft)
self.ft = as_table(ft)
self.islazy = true
return self
end

function use_meta:setup(config)
self.setup = config
return self
end

function use_meta:config(config)
assert(type(config) == 'function')
self.config = config
return self
end

local function info_win()
local bufnr = api.nvim_create_buf(false, false)
local win = api.nvim_open_win(bufnr, true, {
relative = 'editor',
height = math.floor(vim.o.lines * 0.5),
width = math.floor(vim.o.columns * 0.8),
row = 3,
col = 10,
border = 'rounded',
noautocmd = true,
})
vim.wo[win].wrap = false
return win, bufnr
end

local bufnr, winid

local function handle_git_output(index, data)
vim.schedule(function()
if not winid then
winid, bufnr = info_win()
end
api.nvim_buf_set_lines(bufnr, index - 1, index, false, { data })
end)
end

function use_meta:do_action(index, action)
local tail = vim.split(self.name, '/')[2]
local path = vim.fs.joinpath(self.islazy and OPTDIR or STARTDIR, tail)
local url = ('https://github.com/%s'):format(self.name)
local cmd = action == INSTALL and { 'git', 'clone', '--progress', url, path }
or { 'git', '-C', '--progress', path, 'pull' }
uv.fs_stat(path, function(_, stat)
if stat and stat.type == 'directory' then
return
end
coroutine.resume(coroutine.create(function()
local co = assert(coroutine.running())
vim.system(cmd, {
timeout = 5000,
stderr = function(err, data)
coroutine.resume(co, err, data)
end,
})
while true do
local err, data = coroutine.yield()
if not data then
break
end
local lines = err and err or data
lines = lines:gsub('\r', '\n'):gsub('\n+', '\n')
lines = vim.split(lines, '\n', { trimempty = true })
handle_git_output(index, ('%s: %s'):format(self.name, lines[#lines]))
end
end))
end)
end

local function action(act)
local index = 0
vim.iter(repos):map(function(repo)
index = index + 1
repo:do_action(index, act)
end)
end

return {
use = function(name)
local repo = setmetatable({ name = name }, use_meta)
repos[#repos + 1] = repo
return repo
end,
install = function()
action(INSTALL)
end,
update = function()
action(UPDATE)
end,
}
7 changes: 0 additions & 7 deletions lua/nvim-plugin-template/init.lua

This file was deleted.

File renamed without changes.
56 changes: 0 additions & 56 deletions rename.py

This file was deleted.

8 changes: 0 additions & 8 deletions test/plugin_spec.lua
Original file line number Diff line number Diff line change
@@ -1,8 +0,0 @@
local example = require('nvim-plugin-template').example

describe('neovim plugin', function()
it('work as expect', function()
local result = example()
assert.is_true(result)
end)
end)

0 comments on commit 2e94730

Please sign in to comment.