Skip to content

Commit

Permalink
feat(config): the chosen_file_path is configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas committed Apr 7, 2024
1 parent 3a59384 commit 181f156
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
}
```
14 changes: 8 additions & 6 deletions lua/yazi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/yazi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local M = {}
function M.default()
return {
open_for_directories = false,
chosen_file_path = '/tmp/yazi_filechosen',
}
end

Expand Down
1 change: 1 addition & 0 deletions lua/yazi/types.lua
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 181f156

Please sign in to comment.