Skip to content

Commit

Permalink
fix(nvim): simplify mini.files config
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Jul 11, 2023
1 parent 5a5b1c9 commit b833ddd
Showing 1 changed file with 4 additions and 42 deletions.
46 changes: 4 additions & 42 deletions nvim/lua/my/configure/mini_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,10 @@ return {
'<F3>',
function()
local minifiles = require('mini.files')
if vim.bo.filetype == 'minifiles' then
minifiles.close()
else
local current_file = vim.api.nvim_buf_get_name(0)
local is_file = vim.fn.filereadable(current_file) ~= 0
minifiles.open(vim.loop.cwd(), false)
-- reveal current buffer in file tree
if is_file then
vim.schedule(function()
minifiles.reset()
local line = 1
local entry = minifiles.get_fs_entry(0, line)
while entry do
if not entry then
return
end
-- if path matches exactly, we found the file, just set cursor to the right line
if current_file == entry.path then
vim.api.nvim_win_set_cursor(0, { line, 1 })
return
-- if buffer file name has the entry path as a prefix, open the directory
elseif
current_file:find(
-- add trailing slash on directory path to avoid matching substrings
-- like `directory` matching `directory_other`;
-- we make it so `directory/` doesn't match `directory_other/`
string.format('%s/', entry.path),
1,
true
) == 1
then
vim.api.nvim_win_set_cursor(0, { line, 1 })
require('mini.files').go_in()
line = 1
else
line = line + 1
end
entry = minifiles.get_fs_entry(0, line)
end
end)
end
end
local file = vim.api.nvim_buf_get_name(0)
local file_exists = vim.fn.filereadable(file) ~= 0
minifiles.open(file_exists and file or nil)
minifiles.reveal_cwd()
end,
desc = 'Open mini.files',
},
Expand Down

0 comments on commit b833ddd

Please sign in to comment.