mirror of
https://github.com/chenasraf/dotfiles.git
synced 2026-05-18 01:29:06 +00:00
feat: lazygit new plugin wip
This commit is contained in:
71
.config/nvim/lua/casraf/lib/lazygit.lua
Normal file
71
.config/nvim/lua/casraf/lib/lazygit.lua
Normal file
@@ -0,0 +1,71 @@
|
||||
local state = {
|
||||
floating = {
|
||||
buf = -1,
|
||||
win = -1,
|
||||
}
|
||||
}
|
||||
|
||||
local function create_floating_window(opts)
|
||||
opts = opts or {}
|
||||
local width = opts.width or math.floor(vim.o.columns * 0.8)
|
||||
local height = opts.height or math.floor(vim.o.lines * 0.8)
|
||||
|
||||
local col = math.floor((vim.o.columns - width) / 2)
|
||||
local row = math.floor((vim.o.lines - height) / 2)
|
||||
|
||||
local buf = nil
|
||||
if vim.api.nvim_buf_is_valid(opts.buf) then
|
||||
buf = opts.buf
|
||||
else
|
||||
buf = vim.api.nvim_create_buf(false, true) -- No file, scratch buffer
|
||||
end
|
||||
|
||||
local win_config = {
|
||||
relative = 'editor',
|
||||
width = width,
|
||||
height = height,
|
||||
col = col,
|
||||
row = row,
|
||||
style = 'minimal',
|
||||
border = 'rounded',
|
||||
}
|
||||
|
||||
local win = vim.api.nvim_open_win(buf, true, win_config)
|
||||
|
||||
return { buf = buf, win = win }
|
||||
end
|
||||
|
||||
local function toggle_lazygit()
|
||||
if not vim.api.nvim_win_is_valid(state.floating.win) then
|
||||
state.floating = create_floating_window({ buf = state.floating.buf })
|
||||
if vim.bo[state.floating.buf].buftype ~= "terminal" then
|
||||
vim.cmd.terminal("lazygit")
|
||||
vim.keymap.set({ 'n', 'i', 't' }, 'q', toggle_lazygit, { buffer = state.floating.buf })
|
||||
end
|
||||
vim.defer_fn(function()
|
||||
vim.cmd('startinsert')
|
||||
end, 100)
|
||||
else
|
||||
vim.api.nvim_win_hide(state.floating.win)
|
||||
end
|
||||
end
|
||||
|
||||
local function setup(opts)
|
||||
opts = opts or {}
|
||||
vim.api.nvim_create_user_command('LazyGit', toggle_lazygit, { force = true })
|
||||
vim.api.nvim_create_autocmd('WinResized', {
|
||||
callback = function()
|
||||
if not vim.api.nvim_win_is_valid(state.floating.win) then
|
||||
return
|
||||
end
|
||||
|
||||
vim.api.nvim_win_hide(state.floating.win)
|
||||
toggle_lazygit()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local M = {}
|
||||
M.toggle_lazygit = toggle_lazygit
|
||||
M.setup = setup
|
||||
return M
|
||||
@@ -1,16 +1,22 @@
|
||||
-- local home = os.getenv('HOME')
|
||||
-- local lazygit = require('casraf.lib.lazygit')
|
||||
--
|
||||
-- lazygit.setup({})
|
||||
|
||||
return {
|
||||
"chenasraf/lazygit.nvim",
|
||||
branch = "feat/resize",
|
||||
{
|
||||
"chenasraf/lazygit.nvim",
|
||||
branch = "feat/resize",
|
||||
-- enabled = false,
|
||||
|
||||
-- dir = home .. "/Dev/lazygit.nvim",
|
||||
-- dir = home .. "/Dev/lazygit.nvim",
|
||||
|
||||
-- "kdheepak/lazygit.nvim",
|
||||
-- optional for floating window border decoration
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
-- "kdheepak/lazygit.nvim",
|
||||
-- optional for floating window border decoration
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
},
|
||||
config = function()
|
||||
vim.keymap.set('n', '<leader>gs', '<Cmd>LazyGit<CR>', { desc = 'Lazy[G]it', silent = true })
|
||||
end,
|
||||
},
|
||||
config = function()
|
||||
vim.keymap.set('n', '<leader>gs', '<Cmd>LazyGit<CR>', { desc = 'Lazy[G]it', silent = true })
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -85,6 +85,8 @@ vim.keymap.set("v", "<leader>r", [["hy:%s/<C-r>h/<C-r>h/gI<Left><Left><Left>]],
|
||||
--- NOTE general utils/cmds
|
||||
---
|
||||
|
||||
vim.keymap.set("t", "<Esc><Esc>", "<C-\\><C-n>", { desc = "Exit terminal mode" })
|
||||
|
||||
--- serve working directory as web server & open in browser
|
||||
vim.keymap.set("n", "<leader>Srv", function()
|
||||
local cmd = "http-server -p 5500"
|
||||
|
||||
Reference in New Issue
Block a user