-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Mazanov <[email protected]>
- Loading branch information
Showing
8 changed files
with
437 additions
and
42 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleURLTypes</key> | ||
<array> | ||
<dict> | ||
<key>CFBundleTypeRole</key> | ||
<string>Editor</string> | ||
<key>CFBundleURLName</key> | ||
<string>com.ameba.esse.open</string> | ||
<key>CFBundleURLSchemes</key> | ||
<array> | ||
<string>esse</string> | ||
</array> | ||
</dict> | ||
</array> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>Esse</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundleGetInfoString</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>$(MARKETING_VERSION)</string> | ||
<key>CFBundleVersion</key> | ||
<string>218</string> | ||
<key>INIntentsSupported</key> | ||
<array> | ||
<string>RunFunctionIntent</string> | ||
<string>RunFunctionFileIntent</string> | ||
</array> | ||
<key>LSApplicationCategoryType</key> | ||
<string>public.app-category.utilities</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2020 Ameba Labs. All rights reserved.</string> | ||
<key>NSServices</key> | ||
<array> | ||
<dict> | ||
<key>NSKeyEquivalent</key> | ||
<dict> | ||
<key>default</key> | ||
<string>~@^E</string> | ||
</dict> | ||
<key>NSMenuItem</key> | ||
<dict> | ||
<key>default</key> | ||
<string>Send to Esse</string> | ||
</dict> | ||
<key>NSMessage</key> | ||
<string>textServiceHandler</string> | ||
<key>NSPortName</key> | ||
<string>Esse</string> | ||
<key>NSRequiredContext</key> | ||
<dict/> | ||
<key>NSSendTypes</key> | ||
<array> | ||
<string>NSStringPboardType</string> | ||
</array> | ||
</dict> | ||
</array> | ||
<key>NSUbiquitousContainers</key> | ||
<dict> | ||
<key>iCloud.com.ameba.esse</key> | ||
<dict> | ||
<key>NSUbiquitousContainerIsDocumentScopePublic</key> | ||
<true/> | ||
<key>NSUbiquitousContainerName</key> | ||
<string>Esse</string> | ||
<key>NSUbiquitousContainerSupportedFolderLevels</key> | ||
<string>Any</string> | ||
</dict> | ||
</dict> | ||
<key>NSUserActivityTypes</key> | ||
<array> | ||
<string>RunFunctionFileIntent</string> | ||
<string>RunFunctionIntent</string> | ||
<string>TextFunctionIntent</string> | ||
<string>TextIntentIntent</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict/> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import Foundation | ||
import ArgumentParser | ||
import EsseCore | ||
|
||
let storage = Storage.sharedInstance | ||
|
||
struct Esse: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
abstract: "Swiss army knife of text transformation.", | ||
version: "Esse version 2020.5", | ||
subcommands: [List.self] | ||
) | ||
|
||
@Option(name: .short, help: "Transformation(s) to execute.") | ||
var transformations: String? | ||
|
||
@Option(name: .short, help: "Text to transform.") | ||
var input: String? | ||
|
||
mutating func run() throws { | ||
var functions: [TextFunction] = [] | ||
transformations?.split(separator: ",").forEach { id in | ||
guard let f = storage.pAllFunctions.first(where: {$0.id.lowercased().contains(id.lowercased())}) else {return} | ||
functions.append(f) | ||
} | ||
|
||
if let text = input { | ||
print(runFunctions(text: text, functions: functions), terminator:"") | ||
return | ||
} | ||
|
||
let input = FileHandle.standardInput | ||
if let text = String(bytes: input.availableData, encoding: .utf8) { | ||
print(runFunctions(text: text, functions: functions), terminator:"") | ||
return | ||
} | ||
} | ||
|
||
func runFunctions(text: String, functions: [TextFunction]) -> String{ | ||
let actions = functions.compactMap {$0.actions}.flatMap {$0} | ||
return actions.reduce(text) {$1($0)} | ||
} | ||
} | ||
|
||
extension Esse { | ||
struct List: ParsableCommand, Decodable { | ||
static var configuration = | ||
CommandConfiguration(abstract: "Print list of available transformations.") | ||
|
||
@Flag(help: "Print only id.") | ||
var onlyid: Int | ||
|
||
@Flag(help: "Alfred compatible output.") | ||
var alfred: Int | ||
|
||
@Argument(help: "Transfromation.") | ||
var transformation: String? | ||
|
||
|
||
mutating func run() { | ||
storage.reloadExternalFunctions() | ||
var functions = storage.pAllFunctions | ||
if let transformation = transformation { | ||
functions = storage.pAllFunctions.filter({$0.id.lowercased().contains(transformation.lowercased())}) | ||
} | ||
|
||
if functions.isEmpty { | ||
print("No functions found.") | ||
return | ||
} | ||
|
||
if onlyid != 0{ | ||
functions.forEach{print($0.id)} | ||
return | ||
} | ||
|
||
if alfred != 0 { | ||
let alfredItems = functions.map{$0.alfred} | ||
let alfredOutput = TextFunction.AlfredOutput(items: alfredItems) | ||
|
||
let encoder = JSONEncoder() | ||
encoder.outputFormatting = .prettyPrinted | ||
guard let jsonData = try? encoder.encode(alfredOutput), let str = String(data: jsonData, encoding: .utf8) else {return} | ||
print(str) | ||
return | ||
} | ||
functions.forEach{print($0.description)} | ||
} | ||
} | ||
} | ||
|
||
extension TextFunction { | ||
struct AlfredOutput: Codable { | ||
let items: [AlfredItem] | ||
} | ||
struct AlfredItem: Codable { | ||
let uid: String | ||
let title: String | ||
let subtitle: String | ||
var match: String | ||
var arg: String | ||
var autocomplete: String | ||
} | ||
var alfred: AlfredItem { | ||
return AlfredItem(uid: id, title: title, subtitle: desc, match: "\(title) \(desc)", arg: id, autocomplete: title) | ||
} | ||
} | ||
Esse.main() |