nvim/lua/plugins/misc.lua

151 lines
4.1 KiB
Lua
Raw Normal View History

return {
{ 'jghauser/mkdir.nvim', lazy = false },
{
2024-05-31 11:03:10 +02:00
'willothy/nvim-cokeline',
dependencies = {
2024-05-31 11:03:10 +02:00
'nvim-lua/plenary.nvim', -- Required for v0.4.0+
'nvim-tree/nvim-web-devicons', -- If you want devicons
{
2024-05-31 11:03:10 +02:00
'stevearc/resession.nvim',
config = function()
2024-05-31 11:03:10 +02:00
local resession = require 'resession'
resession.setup()
-- Resession does NOTHING automagically, so we have to set up some keymaps
2024-05-31 11:03:10 +02:00
vim.keymap.set('n', '<leader>ss', resession.save)
vim.keymap.set('n', '<leader>sl', resession.load)
vim.keymap.set('n', '<leader>sd', resession.delete)
end,
}, -- Optional, for persistent history
},
2024-05-31 11:03:10 +02:00
event = 'VeryLazy',
keys = {
2024-05-31 11:03:10 +02:00
{ 'gp', '<Plug>(cokeline-focus-prev)', desc = 'next buffer' },
{ 'gn', '<Plug>(cokeline-focus-next)', desc = 'next buffer' },
},
-- opts = {},
config = function()
local get_hex = require('cokeline.hlgroups').get_hl_attr
2024-05-31 11:03:10 +02:00
require('cokeline').setup {
default_hl = {
fg = function(buffer)
2024-05-31 11:03:10 +02:00
return buffer.is_focused and get_hex('Normal', 'fg') or
get_hex('Comment', 'fg')
end,
bg = 'NONE',
},
components = {
{
2024-05-31 11:03:10 +02:00
text = function(buffer)
return (buffer.index ~= 1) and '' or ''
end,
fg = function()
return get_hex('Normal', 'fg')
end,
},
{
2024-05-31 11:03:10 +02:00
text = function(buffer)
return ' ' .. buffer.devicon.icon
end,
fg = function(buffer)
return buffer.devicon.color
end,
},
{
2024-05-31 11:03:10 +02:00
text = function(buffer)
return buffer.filename .. ' '
end,
bold = function(buffer)
return buffer.is_focused
end,
},
{
text = '󰖭',
on_click = function(_, _, _, _, buffer)
buffer:delete()
2024-05-31 11:03:10 +02:00
end,
},
{
text = ' ',
},
},
2024-05-31 11:03:10 +02:00
}
end,
2024-05-28 14:29:11 +02:00
},
{
2024-05-31 11:03:10 +02:00
'willothy/flatten.nvim',
2024-05-28 14:29:11 +02:00
opts = function()
---@type Terminal?
local saved_terminal
return {
window = {
2024-05-31 11:03:10 +02:00
open = 'alternate',
2024-05-28 14:29:11 +02:00
},
callbacks = {
should_block = function(argv)
-- Note that argv contains all the parts of the CLI command, including
-- Neovim's path, commands, options and files.
-- See: :help v:argv
-- In this case, we would block if we find the `-b` flag
-- This allows you to use `nvim -b file1` instead of
-- `nvim --cmd 'let g:flatten_wait=1' file1`
2024-05-31 11:03:10 +02:00
return vim.tbl_contains(argv, '-b')
2024-05-28 14:29:11 +02:00
-- Alternatively, we can block if we find the diff-mode option
-- return vim.tbl_contains(argv, "-d")
end,
pre_open = function()
2024-05-31 11:03:10 +02:00
local term = require 'toggleterm.terminal'
2024-05-28 14:29:11 +02:00
local termid = term.get_focused_id()
saved_terminal = term.get(termid)
end,
post_open = function(bufnr, winnr, ft, is_blocking)
if is_blocking and saved_terminal then
-- Hide the terminal while it's blocking
saved_terminal:close()
else
-- If it's a normal file, just switch to its window
vim.api.nvim_set_current_win(winnr)
-- vim.api.nvim_set_current_bufnr(bufnr)
-- If we're in a different wezterm pane/tab, switch to the current one
-- Requires willothy/wezterm.nvim
-- require("wezterm").switch_pane.id(
-- tonumber(os.getenv("WEZTERM_PANE"))
-- )
end
-- If the file is a git commit, create one-shot autocmd to delete its buffer on write
-- If you just want the toggleable terminal integration, ignore this bit
2024-05-31 11:03:10 +02:00
if ft == 'gitcommit' or ft == 'gitrebase' then
vim.api.nvim_create_autocmd('BufWritePost', {
2024-05-28 14:29:11 +02:00
buffer = bufnr,
once = true,
callback = vim.schedule_wrap(function()
vim.api.nvim_buf_delete(bufnr, {})
end),
})
end
end,
block_end = function()
-- After blocking ends (for a git commit, etc), reopen the terminal
vim.schedule(function()
if saved_terminal then
saved_terminal:open()
saved_terminal = nil
end
end)
end,
},
}
end,
-- or pass configuration with
-- opts = { }
-- Ensure that it runs first to minimize delay when opening file from terminal
lazy = false,
priority = 1001,
},
}