commit a568b40ddc5b75cec37169796e2c4d93cd735ec1 Author: Annika Backstrom Date: Wed Jun 8 22:50:04 2022 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b29812 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/config/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..65403c7 --- /dev/null +++ b/Package.swift @@ -0,0 +1,22 @@ +// swift-tools-version: 5.6 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "fancyclip", + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .executableTarget( + name: "fancyclip", + dependencies: []), + .testTarget( + name: "fancyclipTests", + dependencies: ["fancyclip"]), + ] +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..ab21841 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# fancyclip + +A description of this package. diff --git a/Sources/fancyclip/.main.swift.swp b/Sources/fancyclip/.main.swift.swp new file mode 100644 index 0000000..094450a Binary files /dev/null and b/Sources/fancyclip/.main.swift.swp differ diff --git a/Sources/fancyclip/main.swift b/Sources/fancyclip/main.swift new file mode 100755 index 0000000..9f75d3e --- /dev/null +++ b/Sources/fancyclip/main.swift @@ -0,0 +1,17 @@ +import Foundation +import Cocoa + +let cmd = (CommandLine.arguments[0] as NSString).lastPathComponent + +if CommandLine.arguments.count < 3 { + fputs("usage: \(cmd) LABEL URL\n", stderr) + exit(1) +} + +let label = CommandLine.arguments[1] +let url = CommandLine.arguments[2] + +let pasteBoard = NSPasteboard.general +pasteBoard.clearContents() +pasteBoard.setString("[\(label)](\(url))", forType: .string) +pasteBoard.setString("\(label)", forType: .html) diff --git a/Tests/fancyclipTests/fancyclipTests.swift b/Tests/fancyclipTests/fancyclipTests.swift new file mode 100644 index 0000000..c9d1960 --- /dev/null +++ b/Tests/fancyclipTests/fancyclipTests.swift @@ -0,0 +1,47 @@ +import XCTest +import class Foundation.Bundle + +final class fancyclipTests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + + // Some of the APIs that we use below are available in macOS 10.13 and above. + guard #available(macOS 10.13, *) else { + return + } + + // Mac Catalyst won't have `Process`, but it is supported for executables. + #if !targetEnvironment(macCatalyst) + + let fooBinary = productsDirectory.appendingPathComponent("fancyclip") + + let process = Process() + process.executableURL = fooBinary + + let pipe = Pipe() + process.standardOutput = pipe + + try process.run() + process.waitUntilExit() + + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output = String(data: data, encoding: .utf8) + + XCTAssertEqual(output, "Hello, world!\n") + #endif + } + + /// Returns path to the built products directory. + var productsDirectory: URL { + #if os(macOS) + for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { + return bundle.bundleURL.deletingLastPathComponent() + } + fatalError("couldn't find the products directory") + #else + return Bundle.main.bundleURL + #endif + } +}