Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Aug 9, 2024
1 parent c9357f4 commit 51d6c81
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 40 deletions.
86 changes: 46 additions & 40 deletions lua/minpm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,26 @@ function window:new()
self.__index = self
self.content = {}
self.last_row = -1
vim.schedule(function()
self.bufnr = api.nvim_create_buf(false, false)
self.win = api.nvim_open_win(self.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,
style = 'minimal',
})
vim.wo[self.win].wrap = false
vim.bo[self.bufnr].buftype = 'nofile'
end)
return o
end

function window:creaet()
self.bufnr = api.nvim_create_buf(false, false)
self.win = api.nvim_open_win(self.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,
style = 'minimal',
hide = true,
})
vim.wo[self.win].wrap = false
vim.bo[self.bufnr].buftype = 'nofile'
end

function window:get_row(repo_name)
if not vim.list_contains(self.content, repo_name) then
self.content[#self.content + 1] = repo_name
Expand All @@ -98,6 +100,9 @@ end
function window:write_output(name, data)
local row = self:get_row(name) - 1
vim.schedule(function()
if not self.bufnr then
self:create_window()
end
buf_set_lines(self.bufnr, row, row + 1, false, { ('%s: %s'):format(name, data) })
end)
end
Expand Down Expand Up @@ -134,38 +139,39 @@ function use_meta:do_action(action, winobj)
end

local function action_wrapper(act)
local winobj = window:new()
vim.iter(repos):map(function(repo)
if not repo.remote then
return
end
repo:do_action(act, winobj)
end)
return function()
local winobj = window:new()
vim.iter(repos):map(function(repo)
if not repo.remote then
return
end
repo:do_action(act, winobj)
end)
end
end

if if_nil(vim.g.minpm_auto_install, true) then
create_autocmd('UIEnter', {
callback = function()
action_wrapper(INSTALL)
action_wrapper(INSTALL)()
end,
})
end

return {
use = function(name)
name = vim.fs.normalize(name)
local parts = vim.split(name, '/', { trimempty = true })
repos[#repos + 1] = setmetatable({
name = name,
remote = not name:find(vim.env.HOME),
tail = parts[#parts],
}, use_meta)
return repos[#repos]
end,
install = function()
action_wrapper(INSTALL)
end,
update = function()
action_wrapper(UPDATE)
local function use(name)
name = vim.fs.normalize(name)
local parts = vim.split(name, '/', { trimempty = true })
repos[#repos + 1] = setmetatable({
name = name,
remote = not name:find(vim.env.HOME),
tail = parts[#parts],
}, use_meta)
return repos[#repos]
end

return setmetatable({}, {
__index = function(_, k)
local t = { use = use, complete = { 'install', 'update' } }
return t[k] or action_wrapper(k:upper())
end,
}
})
14 changes: 14 additions & 0 deletions plugin/minpm.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if vim.g.minpm_loaded then
return
end

local api = vim.api

api.nvim_create_user_command('Minpm', function(args)
local sub = args.args
end, {
nargs = '?',
complete = function()
return require('minpm').complete
end,
})

0 comments on commit 51d6c81

Please sign in to comment.