From 18b1eb762556ddf49772faf9049c763331a368e6 Mon Sep 17 00:00:00 2001 From: Mika Vilpas Date: Fri, 19 Jul 2024 12:52:59 +0300 Subject: [PATCH] refactor: reenable the opt-in `--client-id` flag for yazi This reverts commit de4e79e07867c29c871a91d464c421ca1f26ba33. --- lua/yazi/process/legacy_events_from_file.lua | 2 +- lua/yazi/process/ya_process.lua | 32 +++++++++++++------- lua/yazi/yazi_process.lua | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lua/yazi/process/legacy_events_from_file.lua b/lua/yazi/process/legacy_events_from_file.lua index bd3f85cd..7dcc3bc2 100644 --- a/lua/yazi/process/legacy_events_from_file.lua +++ b/lua/yazi/process/legacy_events_from_file.lua @@ -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), diff --git a/lua/yazi/process/ya_process.lua b/lua/yazi/process/ya_process.lua index 958e240e..819f8baa 100644 --- a/lua/yazi/process/ya_process.lua +++ b/lua/yazi/process/ya_process.lua @@ -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 = {} @@ -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 @@ -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() diff --git a/lua/yazi/yazi_process.lua b/lua/yazi/yazi_process.lua index 1f039e78..1e95244b 100644 --- a/lua/yazi/yazi_process.lua +++ b/lua/yazi/yazi_process.lua @@ -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, {