Skip to content

Commit c7b7556

Browse files
committed
support adding scripts
1 parent 1fff3be commit c7b7556

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Flitro/Editor/ContextEditorView.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ struct ContextEditorView: View {
8787
contextManager.saveContexts()
8888
print("Added application: \(appItem.name)")
8989
}
90+
} else if url.pathExtension == "sh" {
91+
// Add as terminal session (shell script)
92+
let session = TerminalSession(
93+
workingDirectory: url.deletingLastPathComponent().path,
94+
command: url.path,
95+
title: url.deletingPathExtension().lastPathComponent
96+
)
97+
contextManager.contexts[contextIndex].terminalSessions.append(session)
98+
contextManager.saveContexts()
99+
print("Added terminal session for script: \(session.title)")
90100
} else {
91101
// Add as document
92102
var bookmark: Data? = nil
@@ -109,6 +119,33 @@ struct ContextEditorView: View {
109119
}
110120
}
111121
handled = true
122+
} else if provider.hasItemConformingToTypeIdentifier("public.shell-script") {
123+
provider.loadItem(forTypeIdentifier: "public.shell-script", options: nil) { item, error in
124+
if let error = error {
125+
print("Error loading shell script: \(error)")
126+
return
127+
}
128+
var url: URL?
129+
if let urlObject = item as? URL {
130+
url = urlObject
131+
} else if let data = item as? Data {
132+
url = URL(dataRepresentation: data, relativeTo: nil)
133+
print("Converted data to URL: \(String(describing: url))")
134+
}
135+
if let url = url {
136+
DispatchQueue.main.async {
137+
let session = TerminalSession(
138+
workingDirectory: url.deletingLastPathComponent().path,
139+
command: url.path,
140+
title: url.deletingPathExtension().lastPathComponent
141+
)
142+
contextManager.contexts[contextIndex].terminalSessions.append(session)
143+
contextManager.saveContexts()
144+
print("Added terminal session for script: \(session.title)")
145+
}
146+
}
147+
}
148+
handled = true
112149
} else if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
113150
provider.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { item, _ in
114151
if let data = item as? Data, let url = URL(dataRepresentation: data, relativeTo: nil) {
@@ -644,4 +681,10 @@ extension View {
644681
}
645682
}
646683

684+
extension UTType {
685+
static var shellScript: UTType {
686+
UTType(importedAs: "public.shell-script")
687+
}
688+
}
689+
647690

0 commit comments

Comments
 (0)