Skip to content

Instantly share code, notes, and snippets.

@ValentinWalter
Created October 17, 2021 13:14
Show Gist options
  • Save ValentinWalter/631f5ad3aba20afe4ee8ee0b3ca4aa00 to your computer and use it in GitHub Desktop.
Save ValentinWalter/631f5ad3aba20afe4ee8ee0b3ca4aa00 to your computer and use it in GitHub Desktop.
A Script Command for Raycast. Creates a gitignore.
#!/usr/bin/swift
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Make Gitignore
// @raycast.mode fullOutput
// Optional parameters:
// @raycast.icon 👻
// @raycast.argument1 { "type": "text", "placeholder": "Search Operating Systems, IDEs, or Programming Languages", "optional": false }
// @raycast.packageName Developer Utilities
// Documentation:
// @raycast.description Creates a gitignore file.
// @raycast.author Valentin Walter
// @raycast.authorURL https://github.com/ValentinWalter
import Foundation
let args = CommandLine.arguments
.dropFirst()
.joined(separator: ",")
let urlString = "https://www.toptal.com/developers/gitignore/api/\(args)"
func error(while action: String) -> Never {
print("""
⛔️ \u{001B}[31mError while \(action).\u{001B}[0m
Attempted URL: \(urlString)
ℹ️ \u{001B}[36mPerhaps you entered an invalid argument.
\u{001B}[0mSee https://www.toptal.com/developers/gitignore/api/list for a \
list of available arguments.
""")
exit(1)
}
guard let url = URL(string: urlString) else { error(while: "parsing the URL") }
guard let data = try? Data(contentsOf: url) else { error(while: "parsing the Data") }
guard let gitignore = String(data: data, encoding: .utf8) else { error(while: "creating the gitignore String") }
print(gitignore)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment