diff --git a/README.md b/README.md index 8cbac21a..5103f89c 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,15 @@ Using lazy.nvim: }, ---@type YaziConfig opts = { + -- Below is the default configuration. It is optional to set these values. + -- + -- enable this if you want to open yazi instead of netrw open_for_directories = false, + + -- the path to a temporary file that will be created by yazi to store the + -- chosen file path + chosen_file_path = '/tmp/yazi_filechosen', }, } ``` diff --git a/lua/yazi.lua b/lua/yazi.lua index 3e3451de..36e7471a 100644 --- a/lua/yazi.lua +++ b/lua/yazi.lua @@ -7,7 +7,6 @@ local M = {} M.yazi_loaded = false -local output_path = '/tmp/yazi_filechosen' local yazi_nvim_events_path = '/tmp/yazi.nvim.events.txt' --- :Yazi entry point @@ -24,11 +23,12 @@ function M.yazi(path) local win, buffer = window.open_floating_window() - os.remove(output_path) + os.remove(M.config.chosen_file_path) local cmd = string.format( - 'yazi "%s" --local-events "rename" --chooser-file "%s" > /tmp/yazi.nvim.events.txt', + 'yazi "%s" --local-events "rename" --chooser-file "%s" > %s', path, - output_path + M.config.chosen_file_path, + yazi_nvim_events_path ) if M.yazi_loaded == false then @@ -49,8 +49,10 @@ function M.yazi(path) ---@cast win integer vim.api.nvim_win_close(win, true) vim.api.nvim_set_current_win(prev_win) - if code == 0 and utils.file_exists(output_path) == true then - local chosen_file = vim.fn.readfile(output_path)[1] + if + code == 0 and utils.file_exists(M.config.chosen_file_path) == true + then + local chosen_file = vim.fn.readfile(M.config.chosen_file_path)[1] if chosen_file then vim.cmd(string.format('edit %s', chosen_file)) end diff --git a/lua/yazi/config.lua b/lua/yazi/config.lua index 50191bc9..7128d002 100644 --- a/lua/yazi/config.lua +++ b/lua/yazi/config.lua @@ -4,6 +4,7 @@ local M = {} function M.default() return { open_for_directories = false, + chosen_file_path = '/tmp/yazi_filechosen', } end diff --git a/lua/yazi/types.lua b/lua/yazi/types.lua index bc04b273..7aae187a 100644 --- a/lua/yazi/types.lua +++ b/lua/yazi/types.lua @@ -1,5 +1,6 @@ ---@class YaziConfig ---@field public open_for_directories boolean +---@field public chosen_file_path string "the path to a temporary file that will be created by yazi to store the chosen file path" ---@class YaziRenameEvent ---@field public type "rename"