Skip to content

Commit

Permalink
refactor: reenable the opt-in --client-id flag for yazi (#229)
Browse files Browse the repository at this point in the history
This reverts commit de4e79e.
  • Loading branch information
mikavilpas authored Jul 19, 2024
1 parent 28f703b commit 305a6a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lua/yazi/process/legacy_events_from_file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function LegacyEventReadingFromEventFile:new(config)
end

---@param path Path
function LegacyEventReadingFromEventFile:get_yazi_command(path, _)
function LegacyEventReadingFromEventFile:get_yazi_command(path)
return string.format(
'yazi %s --local-events "rename,delete,trash,move,cd" --chooser-file "%s" > "%s"',
vim.fn.shellescape(path.filename),
Expand Down
32 changes: 21 additions & 11 deletions lua/yazi/process/ya_process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local highlight_hovered_buffer =
---@field public events YaziEvent[] "The events that have been received from yazi"
---@field public new fun(config: YaziConfig, yazi_id: string): YaProcess
---@field private config YaziConfig
---@field private yazi_id string
---@field private yazi_id? string "The YAZI_ID of the yazi process. Can be nil if this feature is not in use."
---@field private ya_process vim.SystemObj
---@field private retries integer
local YaProcess = {}
Expand All @@ -22,7 +22,11 @@ YaProcess.__index = YaProcess
---@param yazi_id string
function YaProcess.new(config, yazi_id)
local self = setmetatable({}, YaProcess)
self.yazi_id = yazi_id

if config.use_yazi_client_id_flag == true then
self.yazi_id = yazi_id
end

self.config = config
self.events = {}
self.retries = 0
Expand All @@ -31,15 +35,21 @@ function YaProcess.new(config, yazi_id)
end

---@param path Path
---@param yazi_id string
---@diagnostic disable-next-line: unused-local
-- selene: allow(unused_variable)
function YaProcess:get_yazi_command(path, yazi_id)
return string.format(
'yazi %s --chooser-file "%s"',
vim.fn.shellescape(path.filename),
self.config.chosen_file_path
)
function YaProcess:get_yazi_command(path)
if self.yazi_id then
return string.format(
'yazi %s --chooser-file "%s" --client-id "%s"',
vim.fn.shellescape(path.filename),
self.config.chosen_file_path,
self.yazi_id
)
else
return string.format(
'yazi %s --chooser-file "%s"',
vim.fn.shellescape(path.filename),
self.config.chosen_file_path
)
end
end

function YaProcess:kill()
Expand Down
2 changes: 1 addition & 1 deletion lua/yazi/yazi_process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function YaziProcess:start(config, path, on_exit)
and YaProcess.new(config, yazi_id)
or LegacyEventReadingFromEventFile:new(config)

local yazi_cmd = self.event_reader:get_yazi_command(path, yazi_id)
local yazi_cmd = self.event_reader:get_yazi_command(path)
Log:debug(string.format('Opening yazi with the command: (%s).', yazi_cmd))

self.yazi_job_id = vim.fn.termopen(yazi_cmd, {
Expand Down

0 comments on commit 305a6a5

Please sign in to comment.