diff --git a/nvim/lua/my/configure/mini_files.lua b/nvim/lua/my/configure/mini_files.lua index cc06a1bb..efd07fc6 100644 --- a/nvim/lua/my/configure/mini_files.lua +++ b/nvim/lua/my/configure/mini_files.lua @@ -28,48 +28,10 @@ return { '', 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', },