Skip to content

Commit

Permalink
New item for develop menu: Open in iTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Jul 10, 2024
1 parent 418b68a commit 157a9d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Planet/Views/Sidebar/MyPlanetSidebarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ struct MyPlanetSidebarItem: View {
}
}

private func hasiTerm() -> Bool {
NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.googlecode.iterm2") != nil
}

private func hasWorldWideWeb() -> Bool {
NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.iconfactory.WorldWideWeb")
!= nil
Expand Down Expand Up @@ -328,6 +332,15 @@ struct MyPlanetSidebarItem: View {
)
}

private func openiTerm(_ template: Template) {
guard
let appUrl = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.googlecode.iterm2")
else { return }

let url = URL(fileURLWithPath: template.path.path)
NSWorkspace.shared.open([url], withApplicationAt: appUrl, configuration: self.openConfiguration(), completionHandler: nil)
}

@ViewBuilder
private func copyMenu() -> some View {
Button {
Expand Down Expand Up @@ -415,6 +428,15 @@ struct MyPlanetSidebarItem: View {
}
}

if hasiTerm(), let template = planet.template {
Button {
openiTerm(template)
} label: {
Image(systemName: "apple.terminal")
Text("Open in iTerm")
}
}

if let enabled = planet.pinnableEnabled, enabled {
Button {
Task(priority: .background) {
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 2127
CURRENT_PROJECT_VERSION = 2128

0 comments on commit 157a9d8

Please sign in to comment.