🍺 BREW Explorer

← all formulae

swift-sh

brew install swift-sh v2.5.0_1 Unlicense

Swift script runner with inline dependency declarations via import comments.

Why you might care

Eliminates the overhead of a full Swift package for simple scripts: declare dependencies directly in import statements (e.g. `import PromiseKit // @mxcl ~> 6.5`) and run single-file scripts without `swift build`. Useful for Swift developers who want quick automation or one-off tools without project boilerplate.

Categories

Alternatives

swift ruby python
1.8k
30-day installs · #1029
8.1k
90-day · #899
51.1k
365-day · #674
1.9k
★ GitHub stars · updated 17d ago

GitHub topics

scripting swift

Links

Blurb generated by claude-haiku-4-5 on today.

Raw metadata
{
  "aliases": [],
  "alternatives": [
    "swift",
    "ruby",
    "python"
  ],
  "build_dependencies": [],
  "categories": [
    "shell",
    "scripting",
    "interpreter"
  ],
  "caveats": null,
  "conflicts_with": [],
  "dependencies": [],
  "deprecated": 0,
  "deprecation_reason": null,
  "desc": "Scripting with easy zero-conf dependency imports",
  "disable_reason": null,
  "disabled": 0,
  "enrichment_fetched_at": "2026-06-20T23:41:16+00:00",
  "first_seen": "2026-06-20T23:34:18+00:00",
  "full_name": "swift-sh",
  "github_default_branch": "master",
  "github_last_commit_at": "2026-06-03T18:37:10Z",
  "github_readme_excerpt": "# `swift sh` ![badge-platforms] ![badge-languages] [![Build Status](https://travis-ci.com/mxcl/swift-sh.svg)](https://travis-ci.com/mxcl/swift-sh)\n\nWriting Swift scripts is *easy*:\n\n```sh\n$ cat \u003c\u003cEOF \u003e script\n#!/usr/bin/swift\nprint(\"Hi!\")\nEOF\n$ chmod u+x script\n$ ./script\nHi!\n```\n\nSadly, to use third-party dependencies we have to migrate our script to a swift\npackage and use `swift build`, a relatively heavy solution when all we wanted\nwas to whip up a quick script. `swift-sh` gives us the best of both worlds:\n\n```sh\n$ cat \u003c\u003cEOF \u003e script\n#!/usr/bin/swift sh\nimport PromiseKit  // @mxcl ~\u003e 6.5\nprint(Promise.value(\"Hi!\"))\nEOF\n$ chmod u+x script\n$ ./script\nPromise(\"Hi!\")\n```\n\nIn case it\u2019s not clear, `swift-sh` reads the comment after the `import` and\nuses this information to fetch your dependencies.\n\n---\n\nLet\u2019s work through an example: if you had a *single file* called `foo.swift`\nand you wanted to import [mxcl/PromiseKit](https://github.com/mxcl/PromiseKit):\n\n```swift\n#!/usr/bin/swift sh\n\nimport Foundation\nimport PromiseKit  // @mxcl ~\u003e 6.5\n\nfirstly {\n    after(.seconds(2))\n}.then {\n    after(.milliseconds(500))\n}.done {\n    print(\"notice: two and a half seconds elapsed\")\n    exit(0)\n}\n\nRunLoop.main.run()\n```\n\nYou could run it with:\n\n```\n$ swift sh foo.swift\n```\n\nOr to make it more \u201cscripty\u201d, first make it executable:\n\n```\n$ chmod u+x foo.swift\n$ mv foo.swift foo    # optional step!\n```\n\nAnd then run it directly:\n\n```\n$ ./foo\n```\n\n# Sponsorship\n\nIf your company depends on `swift-sh` please consider sponsoring the project.\nOtherwise it is hard for me to justify maintaining it.\n\n# Installation\n\n```\nbrew install swift-sh\n```\n\nOr you can build manually using `swift build`.\n\nInstallation results in a single executable called `swift-sh`, the `swift`\nexecutable will call this (provided it is in your `PATH`) when you type:\n`swift sh`.\n\nWe actively support both Linux and Mac and will support Windows as soon as it is\npossible to do so.\n\n# Usage\n\nAdd the *shebang* as the first li",
  "github_repo": "mxcl/swift-sh",
  "github_stars": 1891,
  "github_topics": [
    "scripting",
    "swift"
  ],
  "homepage": "https://github.com/mxcl/swift-sh",
  "homepage_og_description": null,
  "homepage_og_image": null,
  "homepage_title": null,
  "installs_30d": 1795,
  "installs_365d": 51084,
  "installs_90d": 8060,
  "keg_only": 0,
  "keg_only_reason": null,
  "last_seen": "2026-06-20T23:34:18+00:00",
  "license": "Unlicense",
  "llm_generated_at": "2026-06-20T23:48:31+00:00",
  "llm_model": "claude-haiku-4-5",
  "name": "swift-sh",
  "oldnames": [],
  "one_liner": "Swift script runner with inline dependency declarations via import comments.",
  "optional_dependencies": [],
  "rank_30d": 1029,
  "rank_365d": 674,
  "rank_90d": 899,
  "raw_hash": "92c4caf366c54a8b",
  "recommended_dependencies": [],
  "revision": 1,
  "ruby_source_path": "Formula/s/swift-sh.rb",
  "tap": "homebrew/core",
  "test_dependencies": [],
  "uses_from_macos": [
    {
      "swift": "build"
    }
  ],
  "version_head": "HEAD",
  "version_stable": "2.5.0",
  "versioned_formulae": [],
  "why_use_this": "Eliminates the overhead of a full Swift package for simple scripts: declare dependencies directly in import statements (e.g. `import PromiseKit // @mxcl ~\u003e 6.5`) and run single-file scripts without `swift build`. Useful for Swift developers who want quick automation or one-off tools without project boilerplate."
}