{"id":15067009,"url":"https://github.com/pauljeannot/swiftybash","last_synced_at":"2025-04-10T13:54:06.053Z","repository":{"id":63919631,"uuid":"110463501","full_name":"pauljeannot/SwiftyBash","owner":"pauljeannot","description":"Bash scripting \u0026 piping in Swift made easy !","archived":false,"fork":false,"pushed_at":"2018-03-31T17:34:13.000Z","size":43,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T18:50:33.595Z","etag":null,"topics":["bash","bash-scripting","bashscript","easy","pipe","pipeline","pretty","swift","swift-package-manager","swift4"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pauljeannot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-12T19:47:48.000Z","updated_at":"2024-07-03T19:49:36.000Z","dependencies_parsed_at":"2022-11-29T10:45:16.944Z","dependency_job_id":null,"html_url":"https://github.com/pauljeannot/SwiftyBash","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauljeannot%2FSwiftyBash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauljeannot%2FSwiftyBash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauljeannot%2FSwiftyBash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauljeannot%2FSwiftyBash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pauljeannot","download_url":"https://codeload.github.com/pauljeannot/SwiftyBash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248229315,"owners_count":21068875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","bash-scripting","bashscript","easy","pipe","pipeline","pretty","swift","swift-package-manager","swift4"],"created_at":"2024-09-25T01:15:11.920Z","updated_at":"2025-04-10T13:54:06.031Z","avatar_url":"https://github.com/pauljeannot.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![SwiftyBash Logo : When Bash meets Swift](/swiftybash.png)\n\n![Swift 4.1 Badge](https://img.shields.io/badge/Swift-4.1-brightgreen.svg)\n[![Travis Badge](https://travis-ci.org/pauljeannot/SwiftyBash.svg?branch=master)](https://travis-ci.org/pauljeannot/SwiftyBash)\n![Plateform](https://img.shields.io/badge/Plateform-Mac%20%26%20Linux-lightgrey.svg)\n\nSwiftyBash is a Swift Bash scripting \u0026amp; piping library, written in Swift.\n\n## 🤖 Usage\n\n### 🚀 Simple bash command\n\nDescribe your command through a `BashCmd` object, and run it! It is that simple :\n\n```swift\n// Run `ls` in the executable directory\nlet ls = BashCmd(\"ls\")\nlet result = try! ls.run()\n\n// Run `git status` from ~/MyProject directory\nlet status = BashCmd(\"git\", args:\"status\", from:\"~/MyProject\")\nlet result = try! status.run()\n```\n\n### 🤝 Pipe\n\nYou can pipe output and input stream easily, as many times as you want !\n\n```swift\nlet ls = BashCmd(\"ls\", args:\"-l\", from:\"~/\")\nlet grep = BashCmd(\"grep\", args:\"root\")\nlet wc = BashCmd(\"wc\", args:\"-l\")\n\n// Use pipe() function\nlet result = try! ls.pipe(grep).pipe(wc).run()\n```\n\n#### Custom operator\n\nYou can use the `|` to pipe from a command to another 😻\n\n⚠️ You have to declare the operator somewhere in your project to be able to use it !\n\n```swift\n// Operator declaration somewhere in your project\ninfix operator |\n\n// Have fun ! How beautiful is it ?\nlet result = try! (ls | grep | wc).run()\n```\n\n### 🔥 Error handling\n\nSwiftyBash uses Swift exception to handle error, by throwing a BashException.\n\n```swift\nlet grep = BashCmd(\"grep\", args:\"hosts\", \"/private/etc/*\")\ndo {\n  try grep.run()\n}\ncatch {\n  if let error = error as? BashException {\n    print(error.stderr) // Prints STDERR\n    print(error.stdout) // Prints STDOUT\n  }\n}\n\n```\n\n### ✏️ Output type\n\nYou can chose the output type between a simple `String` or to write the output into a file.\nDefault is `.string(.raw)`.\n\n#### Write into a file\n```swift\nlet cat = BashCmd(\"cat\", args:\"file.json\")\nlet grep = BashCmd(\"grep\", args:\"'secrets'\")\n\n// Write the result into `secrets.json`\ntry! (cat | grep).run(outputType:.file(\"secrets.json\"))\n```\n\n#### Whitespaces trimming\n```swift\nlet ls = BashCmd(\"ls\", args:\"-l\")\nlet wc = BashCmd(\"wc\", args:\"-l\")\n\nlet result = try! (ls | wc).run(outputType:.string(.raw))                 // result is `       6`\nlet result = try! (ls | wc).run(outputType:.string(.whiteSpacesTrimmed))  // result is `6`\n```\n\n#### Example of output\n\nWhen taking the output as a string or to a file, new lines (`\\n`) are kept. So, here is an example of output :\n\n```swift\nlet ls = BashCmd(\"ls\", args:\"-l\")\nlet result = try! ls.run()\nprint(result!)\n```\n*... shows ...*\n```bash\ntotal 24\n-rw-r--r--+ 1 me  staff  331 12 nov 23:33 Package.resolved\n-rw-r--r--+ 1 me  staff  743 12 nov 23:19 Package.swift\n-rw-r--r--+ 1 me  staff   50 12 nov 23:02 README.md\ndrwxr-xr-x+ 3 me  staff  102 12 nov 23:02 Sources\ndrwxr-xr-x+ 2 me  staff   68 12 nov 23:02 Tests\n```\n\n## 🚧 Installation\n\nSwiftyBash is currently only available for **Swift 4**. If you need Swift 3 compatibility, feel free to open an issue or to create a Pull Request 😉\n\n### 📦 Swift Package Manager\n\nUpdate your Package.swift file by adding this line to your dependencies :\n\n```swift\n    dependencies: [\n      [...]\n      .package(url: \"https://github.com/pauljeannot/SwiftyBash.git\", from: \"1.0.0\"),\n    ]\n```\n\nDo not forget to also add it to your target dependencies :\n\n```swift\n    targets: [\n        .target(\n            name: \"YourProject\",\n            dependencies: [\"...\", \"SwiftyBash\"]),\n    ]\n```\n\n## 👤 Contact\n\nIf you have any question, new idea or if you find a bug (❌), feel free to open an issue or to contact me by [email](paul.jeannot95@gmail.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauljeannot%2Fswiftybash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpauljeannot%2Fswiftybash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauljeannot%2Fswiftybash/lists"}