another day

This commit is contained in:
Iwaniuk Krzysztof 2024-06-19 00:41:29 +02:00
parent feb59d91c5
commit 1bbc50e3a9
27 changed files with 419 additions and 246 deletions

View file

@ -3,77 +3,33 @@ return {
dependencies = { 'nvim-tree/nvim-web-devicons' },
event = 'VimEnter',
keys = {
{
'qq',
function()
require('oil').close()
end,
mode = '',
desc = 'Close current window',
},
{
'<leader>tn',
function()
local val = require('fancyutil').get_oil_nnn()
if val == true then
vim.api.nvim_buf_set_var(bufnr, 'nnn', false)
elseif val == false then
vim.api.nvim_buf_set_var(bufnr, 'nnn', true)
end
end,
mode = '',
desc = '[T]oggle [n]nn Mode',
},
{
'~',
'<CMD>Oil<CR>',
mode = '',
desc = 'Open parent directory',
},
{
'<Left>',
function()
if require('oil.util').is_oil_bufnr(0) and require('fancyutil').get_oil_nnn() then
local oil = require 'oil'
local bufname = vim.api.nvim_buf_get_name(0)
local parent = oil.get_buffer_parent_url(bufname, true)
return oil.open(parent)
end
-- fallback to sending page up key
local keys = vim.api.nvim_replace_termcodes('<Left>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false)
end,
mode = '',
desc = 'Move up the file tree',
},
{
'<Right>',
function()
local oil = require 'oil'
local entry = oil.get_cursor_entry()
local dir = oil.get_current_dir()
if entry and dir and require('fancyutil').get_oil_nnn() then
local path = dir .. entry.name
local stat = vim.loop.fs_stat(path)
if stat and stat.type == 'directory' then
return oil.open(path)
end
end
-- fallback to sending arrow key
local keys = vim.api.nvim_replace_termcodes('<Right>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false)
end,
mode = '',
desc = 'Move down the file tree',
},
},
opts = {
default_file_explorer = true,
restore_window_options = true,
keymaps = {
['gd'] = {
desc = 'Toggle file detail view',
callback = function()
vim.g.detail = not vim.g.detail
if vim.g.detail then
require('oil').set_columns { 'icon', 'permissions', 'size', 'mtime' }
else
require('oil').set_columns { 'icon' }
end
end,
},
},
win_options = {
wrap = true,
signcolumn = 'yes',
-- signcolumn = '',
cursorcolumn = false,
foldcolumn = '0',
spell = false,
@ -88,29 +44,57 @@ return {
return name:match '.git'
end,
},
-- group = aug,
extensions = {
'oil',
},
},
config = function(_, opts)
local oil = require 'oil'
oil.setup(opts)
end,
init = function()
vim.api.nvim_create_autocmd('BufEnter', {
desc = 'Detect buffer and setup oil nnn flag',
-- group = aug,
pattern = '*',
nested = true,
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWinEnter' }, {
pattern = 'oil://*',
callback = function(params)
local bufnr = params.buf
local _, filetype = pcall(vim.api.nvim_get_option_value, 'filetype', { buf = bufnr })
if filetype == 'oil' then
local val = require('fancyutil').get_oil_nnn(bufnr)
if val == nil then
vim.api.nvim_buf_set_var(bufnr, 'nnn', true)
end
if params.event == 'BufEnter' then
-- double Q to close window
vim.keymap.set('', 'qq', require('oil').close, { buffer = bufnr, desc = 'Close current window' })
-- toggle detailed list mode
vim.keymap.set('', '<leader>tnnn', function()
local fu = require 'fancyutil'
local winnr = 0
local val = fu.get_oil_nnn(winnr)
fu.set_oil_nnn(val ~= true, winnr)
end, { buffer = bufnr, desc = '[T]oggle [nnn] Mode' })
--- nnn move up file tree
vim.keymap.set('', '<Left>', function()
if require('oil.util').is_oil_bufnr(bufnr) and require('fancyutil').get_oil_nnn() then
local oil = require 'oil'
local bufname = vim.api.nvim_buf_get_name(bufnr)
local parent = oil.get_buffer_parent_url(bufname, true)
return oil.open(parent)
end
local keys = vim.api.nvim_replace_termcodes('<Left>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false) -- send consumed keys
end, { buffer = bufnr, desc = 'Move up the file tree' })
-- nnn move down file tree
vim.keymap.set('', '<Right>', function()
local oil = require 'oil'
local entry = oil.get_cursor_entry()
local dir = oil.get_current_dir()
if entry and dir and require('fancyutil').get_oil_nnn(0) then
local path = dir .. entry.name
local stat = vim.loop.fs_stat(path)
if stat and stat.type == 'directory' then
return oil.open(path)
end
end
local keys = vim.api.nvim_replace_termcodes('<Right>', true, false, true)
vim.api.nvim_feedkeys(keys, 'n', false) -- send consumed keys
end, { buffer = bufnr, desc = 'Move down the file tree' })
return
end
local winnr = vim.fn.bufwinid(bufnr)
local val = require('fancyutil').get_oil_nnn(winnr)
if val == nil then
require('fancyutil').set_oil_nnn(true, winnr)
end
end,
})