Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions switchboard/Utilities/AppleScriptTemplates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ enum AppleScriptTemplates {
activate
end tell

delay 0.5
delay 0.8

tell application "System Events"
tell process "Warp"
keystroke "n" using command down
delay 0.3
delay 1.0
keystroke "assume '\(escapedProfile)'"
keystroke return
end tell
Expand All @@ -107,12 +107,12 @@ enum AppleScriptTemplates {
activate
end tell

delay 0.5
delay 0.8

tell application "System Events"
tell process "Warp"
keystroke "n" using command down
delay 0.3
delay 1.0
keystroke "assume -c '\(escapedProfile)'"
keystroke return
end tell
Expand All @@ -136,7 +136,9 @@ enum GhosttyCommands {
static func ghosttyArgs(profileName: String, forConsole: Bool) -> [String] {
let escapedProfile = profileName.escapedForShell
let assumeCmd = forConsole ? "assume -c" : "assume"
return ["-e", "bash", "-c", "\(assumeCmd) '\(escapedProfile)'; exec bash"]
let userShell = ProcessInfo.processInfo.environment["SHELL"] ?? "/bin/zsh"
let shellName = URL(fileURLWithPath: userShell).lastPathComponent
return ["-e", userShell, "-l", "-c", "\(assumeCmd) '\(escapedProfile)'; exec \(shellName)"]
}
}

Expand Down
16 changes: 13 additions & 3 deletions tests/StringEscapingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,27 @@ final class StringEscapingTests: XCTestCase {

func testGhosttyCommand_Assume() {
let args = GhosttyCommands.ghosttyArgs(profileName: "test-profile", forConsole: false)
XCTAssertEqual(args, ["-e", "bash", "-c", "assume 'test-profile'; exec bash"])
XCTAssertEqual(args[0], "-e")
XCTAssertEqual(args[2], "-l")
XCTAssertEqual(args[3], "-c")
XCTAssertTrue(args[4].contains("assume 'test-profile'"))
XCTAssertFalse(args[4].contains("assume -c"))
}

func testGhosttyCommand_AssumeConsole() {
let args = GhosttyCommands.ghosttyArgs(profileName: "test-profile", forConsole: true)
XCTAssertEqual(args, ["-e", "bash", "-c", "assume -c 'test-profile'; exec bash"])
XCTAssertEqual(args[0], "-e")
XCTAssertEqual(args[2], "-l")
XCTAssertEqual(args[3], "-c")
XCTAssertTrue(args[4].contains("assume -c 'test-profile'"))
}

func testGhosttyCommand_WithQuotesInProfile() {
let args = GhosttyCommands.ghosttyArgs(profileName: "it's-my-profile", forConsole: false)
XCTAssertEqual(args, ["-e", "bash", "-c", "assume 'it'\\''s-my-profile'; exec bash"])
XCTAssertEqual(args[0], "-e")
XCTAssertEqual(args[2], "-l")
XCTAssertEqual(args[3], "-c")
XCTAssertTrue(args[4].contains("assume 'it'\\''s-my-profile'"))
}

// MARK: - Edge Cases
Expand Down