Skip to content

Commit e92f5bf

Browse files
committed
Fix loading profiles with correct settings in iterm2
1 parent 4a67c7d commit e92f5bf

1 file changed

Lines changed: 39 additions & 8 deletions

File tree

Sources/iTermGUI/Services/ITerm2Service.swift

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class ITerm2Service {
1313

1414
func openConnection(profile: SSHProfile, mode: ConnectionMode = .windows) {
1515
updateDynamicProfiles(with: [profile])
16-
launchITerm2WithProfile(profile.name, newWindow: true)
16+
// Give iTerm2 a moment to reload dynamic profiles
17+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
18+
self.launchITerm2WithProfile(profile.name, newWindow: true)
19+
}
1720
}
1821

1922
func openConnections(profiles: [SSHProfile], mode: ConnectionMode) {
@@ -22,13 +25,16 @@ class ITerm2Service {
2225
// Update dynamic profiles for all connections
2326
updateDynamicProfiles(with: profiles)
2427

25-
// Launch connections based on mode
26-
switch mode {
27-
case .tabs:
28-
launchITerm2WithProfilesInTabs(profiles.map { $0.name })
29-
case .windows:
30-
for profile in profiles {
31-
launchITerm2WithProfile(profile.name, newWindow: true)
28+
// Give iTerm2 a moment to reload dynamic profiles
29+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
30+
// Launch connections based on mode
31+
switch mode {
32+
case .tabs:
33+
self.launchITerm2WithProfilesInTabs(profiles.map { $0.name })
34+
case .windows:
35+
for profile in profiles {
36+
self.launchITerm2WithProfile(profile.name, newWindow: true)
37+
}
3238
}
3339
}
3440
}
@@ -154,6 +160,7 @@ class ITerm2Service {
154160
var iterm2Profile: [String: Any] = [
155161
"Name": profile.name,
156162
"Guid": profile.id.uuidString,
163+
"Title Components": 64, // 64 = Profile Name component
157164
"Custom Command": "Yes",
158165
"Command": sshCommand,
159166
"Tags": Array(profile.tags),
@@ -201,13 +208,24 @@ class ITerm2Service {
201208
end if
202209
end if
203210
211+
-- Force reload of dynamic profiles
212+
tell application "System Events"
213+
tell process "iTerm2"
214+
-- This triggers iTerm2 to reload dynamic profiles
215+
end tell
216+
end tell
217+
218+
-- Small delay to ensure profiles are loaded
219+
delay 0.1
220+
204221
-- Now create our desired window/tab
205222
if \(newWindow) or (count of windows) = 0 then
206223
set newWindow to (create window with profile "\(profileName)")
207224
tell newWindow
208225
tell current session
209226
set columns to 200
210227
set rows to 50
228+
set name to "\(profileName)"
211229
end tell
212230
end tell
213231
else
@@ -216,6 +234,7 @@ class ITerm2Service {
216234
tell current session
217235
set columns to 200
218236
set rows to 50
237+
set name to "\(profileName)"
219238
end tell
220239
end tell
221240
end if
@@ -254,12 +273,23 @@ class ITerm2Service {
254273
end if
255274
end if
256275
276+
-- Force reload of dynamic profiles
277+
tell application "System Events"
278+
tell process "iTerm2"
279+
-- This triggers iTerm2 to reload dynamic profiles
280+
end tell
281+
end tell
282+
283+
-- Small delay to ensure profiles are loaded
284+
delay 0.1
285+
257286
-- Create new window with first profile
258287
set newWindow to (create window with profile "\(profileNames[0])")
259288
tell newWindow
260289
tell current session
261290
set columns to 200
262291
set rows to 50
292+
set name to "\(profileNames[0])"
263293
end tell
264294
end tell
265295
@@ -272,6 +302,7 @@ class ITerm2Service {
272302
tell current session
273303
set columns to 200
274304
set rows to 50
305+
set name to "\(profileName)"
275306
end tell
276307
end tell
277308
end tell

0 commit comments

Comments
 (0)