Spawn SSH directly on startup instead of a local shell first

The old update-right-status auto-attach flashed a local cmd.exe tab
first and only attached the SSH domain after a delay once the mux
had registered it, so startup never actually connected immediately.
Now gui-startup spawns the first configured SSH domain's `ssh ...`
command directly as the window's first program, so there's no local
shell tab and no attach-timing race to work around.
This commit is contained in:
2026-07-25 19:10:37 +09:00
parent f9be9b3a6d
commit 2de7e3a2bb

View File

@@ -94,24 +94,7 @@ end)
-- ------------------------------------------------------------
local pane_start_times = {}
-- gui-startup 시점엔 SSH 도메인이 아직 mux에 등록되기 전이라 바로 접속을 시도하면 항상
-- "domain name is invalid" 에러가 난다 (고정 지연 0.5초/2초 모두 시도했지만 재현됨).
-- 대신 창이 실제로 정상 작동 중일 때만 도는 update-right-status 훅에서 딱 한 번,
-- 등록된 SSH 도메인이 있으면 그걸로 자동 접속한다 (특정 이름 하드코딩 없음)
local startup_ssh_connect_tried = false
wezterm.on("update-right-status", function(window, pane)
if not startup_ssh_connect_tried then
startup_ssh_connect_tried = true
local first_domain = config.ssh_domains and config.ssh_domains[1]
if first_domain then
-- 아직 attach 안 된 도메인에 SpawnTab을 쓰면 "암묵적 attach가 만드는 기본 탭" +
-- "명시적으로 요청한 탭"이 겹쳐서 탭이 2개 생긴다. AttachDomain은 attach와 동시에
-- 탭이 없을 때만 하나 만들어주므로 중복이 없다.
window:perform_action(act.AttachDomain(first_domain.name), pane)
end
end
local pane_id = pane:pane_id()
if not pane_start_times[pane_id] then
pane_start_times[pane_id] = os.time()
@@ -827,9 +810,31 @@ end)
-- 시작 시 첫 화면으로 메인 메뉴를 띄워 설정과 연결 메뉴에 바로 접근합니다.
-- SSH 자동 접속은 update-right-status 훅에서 처리 (위 pane_start_times 근처 참고)
--
-- update-right-status 훅에서 지연 접속을 시도하던 예전 방식은 로컬 셸(cmd.exe) 탭이
-- 먼저 보였다가 뒤늦게 SSH 탭이 따로 생기는 형태라 "cmd가 잠깐 보였다 바뀌는" 것처럼
-- 느껴지고, 첫 도메인이 mux에 실제로 붙기까지 딜레이도 있었다. 대신 여기서 첫 번째 SSH
-- 도메인의 접속 정보로 곧장 `ssh ...` 명령을 만들어 그 창의 첫 프로그램으로 실행한다.
-- (네이티브 ssh_domains/AttachDomain이 아니라 일반 ssh 클라이언트를 그대로 띄우는 것이라,
-- config.ssh_domains 등록 시점 문제 없이 항상 즉시 연결된다. 로컬 셸이 필요하면 메인
-- 메뉴나 leader+e/leader+Tab 런처에서 언제든 새로 열 수 있다.)
wezterm.on("gui-startup", function(cmd)
local tab, pane, window = wezterm.mux.spawn_window(cmd or {})
local spawn_cmd = cmd
if not spawn_cmd then
local first_domain = config.ssh_domains and config.ssh_domains[1]
if first_domain then
local host, port = split_remote_address(first_domain.remote_address)
local args = { "ssh" }
if port then
table.insert(args, "-p")
table.insert(args, port)
end
table.insert(args, first_domain.username .. "@" .. host)
spawn_cmd = { args = args }
end
end
local tab, pane, window = wezterm.mux.spawn_window(spawn_cmd or {})
list_system_fonts() -- 폰트 목록을 미리 캐싱해서, 나중에 폰트 설정 메뉴에서 조회 지연으로 화면이 깜빡이지 않게 함
show_main_menu(window:gui_window(), pane)
end)