HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
mxcl
swift-sh
Swift2019–2025
mxcl / swift-sh

swift-sh

Easily script with third-party Swift dependencies.

8Distinct people
9Mentions
0Explicit recommenders
1.9KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Easily script with third-party Swift dependencies.

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:03:16 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year9 dated mentions

Observed mentions: 2019-01-13 17:59:03 UTC to 2025-08-10 21:21:46 UTC.

012342019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 4 mentions; 3 submissions, 1 comments20192020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments20222023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 2 mentions; 1 submissions, 1 comments2025

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC431
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC000
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC000
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC101
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC202
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC000
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC211

What Hacker News says

9 sources
I recently learned about swift-sh [1] which is the same thing as “uv run —script” but for swift files. I’ve been having a blast automating some macOS annoyances with small scripts that can use native macOS APIs directly, no more pyobjc. I also wrote an app to bring the startup folder functionality from Windows to the Mac to help me run these scripts at startup more easily [2] [1] https://github.com/mxcl/swift-sh [2] https://github.com/FuzzyIdeas/StartupFolder
In Using uv as your shebang line
Beyond the basics, the shell features with the biggest ROI beyond the basics are to quote properly and use namerefs and arrays (esp. to return values from functions), e.g., # find2ra arrayName {find arguments...} # Run find command and put results in array arrayName. find2ra() { # (error checking removed) local -r f2raVar="${1}" shift # map find entries to ra, using char=0 as delimiter mapfile -d $'\0' -t "$f2raVar" < <(find -dsx "${@}" -print0) # -print0: handle paths with spaces, etc. # -ds: For consistency, use depth-first, lexigraphic order # -x: Avoid traversing other devices } # sample usage ra=() find2ra ra . -type f -name \*.sh for shFile in "${ra[@]}"; do ... ; done There are many resources for shell scripts already. A good starting-point might be to list the awesome shell-scrip
Read the rest
t sample sites already available. The effort to document shell is also somewhat Pyrrhic. The benefit would be... more shell? A more modern shell? Another goal might be to switch to a real language sooner. Go and Python are the obvious choices, but Swift and Java also support shebang's: #!/usr/bin/env swift #!/usr/bin/env java --source 17 Dependencies are always tricky. swift-sh allows you to declare dependencies as comments after the import: import PromiseKit // @mxcl ~> 6.5 https://github.com/mxcl/swift-sh
In Ask HN: Share a shell script you like
Yes, swift CLI will compile and run your swift file. But many people also want to use libraries. For Python, they use the system libraries or work within an environment with installed libraries (i.e., the library-install process happens at environment-configuration time). In Swift, the easiest way to consume libraries is using packages, but that requires a Package.swift declaring the project scope for the script file (which must comply with top-level and main-entrypoint code requirements). The easiest way to do that when scripting is a swift tool that manages the process of gathering your library dependencies, auto-generating a project, building the tool, and caching it all so there's no overhead the next time. The best available tool now is https://github.com/mxcl/swift-sh. It reads dependency information off import comments. It can als
Read the rest
o generate the project for you, if/when you want to build in XCode (e.g., move into a more complex application, perhaps requiring sandbox declarations). Working scripts are not always updated, so any script-build tool has to maintain backwards compatibility, but the swift package manager has changed a lot in recent versions. swift-sh seems to err on the side of backwards compatibility, and does not support e.g., the most recent dependency versioning styles. Swift-forum discussions about better support for scripting haven't resulted in any official tooling.
In Using Swift for Scripting (2019)
Interesting. I've resisted the pull of the Nix side so far... There's a similar package that auto-pulls dependencies for Swift scripts, but it requires you to explicitly state the external dependencies as comment annotations. The example given is: #!/usr/bin/swift sh import Foundation import PromiseKit // @mxcl ~> 6.5 firstly { after(.seconds(2)) }.then { after(.milliseconds(500)) }.done { print("notice: two and a half seconds elapsed") exit(0) } RunLoop.main.run() https://github.com/mxcl/swift-sh
In On env Shebangs
The tricky part is that it is impossible to import any libraries in a script except: - The official libraries that ship with Swift - If you create a full-blown Swift package manager project and compile an executable. But this doesn't sound like a script anymore - If you use John Sundell's Marathon [https://github.com/JohnSundell/Marathon] however it adds additional complexity around the writing of scripts I.e. none of the solutions are as simple as writing a bash script Edit: Just saw that Max Howell (creator of Homebrew) released this today https://github.com/mxcl/swift-sh This absolutely solves the issues. Fantastic.
In Writing custom tools with Swift

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.