Fix SSH domain menu persistence

This commit is contained in:
2026-07-17 01:06:19 +09:00
parent fb37c2ff50
commit 0876d2656c

View File

@@ -148,7 +148,7 @@ config.unix_domains = {
} }
local is_windows = wezterm.target_triple:find("windows") ~= nil local is_windows = wezterm.target_triple:find("windows") ~= nil
local config_file = is_windows and (wezterm.home_dir .. "\\.wezterm.lua") or "/mnt/storage/wezterm.lua" local config_file = wezterm.config_file or (is_windows and (wezterm.home_dir .. "\\.wezterm.lua") or "/mnt/storage/wezterm.lua")
local function notify(window, message) local function notify(window, message)
if window.toast_notification then if window.toast_notification then
@@ -257,12 +257,10 @@ local function append_ssh_domain(window, pane, name, remote_address, username)
end end
local entry = string.format('\t{\n\t\tname = %q,\n\t\tremote_address = %q,\n\t\tusername = %q,\n\t},\n', name, remote_address, username) local entry = string.format('\t{\n\t\tname = %q,\n\t\tremote_address = %q,\n\t\tusername = %q,\n\t},\n', name, remote_address, username)
local updated, count = text:gsub("(config%.ssh_domains%s*=%s*{%s*\n)", function(prefix) local updated, count = text:gsub("\n}%s*\n\n%-%- Unix domain", "\n" .. entry .. "}\n\n-- Unix domain", 1)
return prefix .. entry
end, 1)
if count == 0 then if count == 0 then
notify(window, "config.ssh_domains 블록을 찾지 못했습니다") notify(window, "config.ssh_domains 끝 위치를 찾지 못했습니다")
return return
end end
@@ -272,44 +270,27 @@ local function append_ssh_domain(window, pane, name, remote_address, username)
return return
end end
notify(window, "SSH 도메인 추가됨: " .. name) notify(window, "SSH 도메인 저장됨: " .. name .. " -> " .. remote_address .. " (" .. config_file .. ")")
window:perform_action(act.ReloadConfiguration, pane) window:perform_action(act.ReloadConfiguration, pane)
end end
local function prompt_ssh_domain(window, pane) local function prompt_ssh_domain(window, pane)
local draft = {}
window:perform_action( window:perform_action(
act.PromptInputLine({ act.PromptInputLine({
description = "SSH 이름", description = "SSH 도메인 추가: 이름,주소,사용자명",
action = wezterm.action_callback(function(w1, p1, name) initial_value = "myserver,myserver.example.com,youruser",
if not name or name == "" then action = wezterm.action_callback(function(inner_window, inner_pane, line)
if not line or line == "" then
return return
end end
draft.name = name
w1:perform_action( local name, remote_address, username = line:match("^%s*([^,]+)%s*,%s*([^,]+)%s*,%s*([^,]+)%s*$")
act.PromptInputLine({ if not name or not remote_address or not username then
description = "SSH 주소", notify(inner_window, "형식: 이름,주소,사용자명 예: prod,10.0.0.10,ubuntu")
action = wezterm.action_callback(function(w2, p2, address)
if not address or address == "" then
return return
end end
draft.remote_address = address
w2:perform_action( append_ssh_domain(inner_window, inner_pane, name, remote_address, username)
act.PromptInputLine({
description = "SSH 사용자명",
action = wezterm.action_callback(function(w3, p3, username)
if not username or username == "" then
return
end
append_ssh_domain(w3, p3, draft.name, draft.remote_address, username)
end),
}),
p2
)
end),
}),
p1
)
end), end),
}), }),
pane pane