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