Trên GitHub, mxcl/swift-sh đã đạt 1.9k sao, nhóm Mobile, ngôn ngữ Swift. Easily script with third-party Swift dependencies.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Sadly, to use third-party dependencies we have to migrate our script to a swift
package and use swift build, a relatively heavy solution when all we wanted
was to whip up a quick script. swift-sh gives us the best of both worlds:
If your company depends on swift-sh please consider sponsoring the project.
Otherwise it is hard for me to justify maintaining it.
Installation
brew install swift-sh
Or you can build manually using swift build.
Installation results in a single executable called swift-sh, the swift
executable will call this (provided it is in your PATH) when you type:
swift sh.
We actively support both Linux and Mac and will support Windows as soon as it is
possible to do so.
Usage
Add the shebang as the first line in your script: #!/usr/bin/swift sh.
Your dependencies are determined via your import lines:
#!/usr/bin/swift sh
import AppUpdater // @mxcl
// ^^ https://github.com/mxcl/AppUpdater, latest version
import PromiseKit // @mxcl ~> 6.5
// ^^ mxcl/PromiseKit, version 6.5.0 or higher up to but not including 7.0.0 or higher
import Chalk // @mxcl == 0.3.1
// ^^ mxcl/Chalk, only version 0.3.1
import LegibleError // @mxcl == b4de8c12
// ^^ mxcl/LegibleError, the precise commit `b4de8c12`
import Path // mxcl/Path.swift ~> 0.16
// ^^ for when the module-name and repo-name are not identical
import BumbleButt // https://example.com/bb.git ~> 9
// ^^ non-GitHub URLs are fine
import CommonTaDa // [email protected]:mxcl/tada.git ~> 1
// ^^ ssh URLs are fine
import TaDa // ssh://[email protected]:mxcl/tada.git ~> 1
// ^^ this style of ssh URL is also fine
import Foo // ./my/project
import Bar // ../my/other/project
import Baz // ~/my/other/other/project
import Fuz // /I/have/many/projects
// ^^ local dependencies must expose library products in their `Package.swift`
// careful: `foo/bar` will be treated as a GitHub dependency; prefix with `./`
// local dependencies do *not* need to be versioned
import Floibles // @mxcl ~> 1.0.0-alpha.1
import Bloibles // @mxcl == 1.0.0-alpha.1
// ^^ alphas/betas will only be fetched if you specify them explicitly like so
// this is per Semantic Versioning guidelines
swift-sh reads the comments after your imports and fetches the requested
SwiftPM dependencies.
It is not necessary to add a comment specification for transitive dependencies.
Editing in Xcode
The following will generate an Xcode project (not in the working directory, we
keep it out the way in our cache directory) and open it, edits are saved to your
script file.
$ swift sh edit ./myScript
Examples
Tweet deleter
PostgreSQL Check
Converting your script to a package
Simple scripts can quickly become bigger projects that would benefit from being
packages that you build with SwiftPM. To help you migrate your project we
provide swift sh eject, for example:
$ swift sh eject foo.swift
creates a Swift package in ./Foo, from now on use swift build in the
Foo directory. Your script is now ./Foo/Sources/main.swift.
Use in CI
If you want to make scripts available to people using CI; use stdin:
brew install mxcl/made/swift-sh
swift sh <(curl http://example.com/yourscript) arg1 arg2
Internal Details
swift sh creates a Swift Package.swift package manager project with
dependencies in a directory below the swift-sh cache directory †,
builds the executable, and then executes it via swift run.
The script is (only) rebuilt when the script file is newer than the executable.
† Specify the cache parent directory using the (FreeDesktop) environment
variable XDG_CACHE_HOME. If unspecified, on macOS swif-sh uses
$HOME/Library/Developer/swift-sh.cache, and otherwise it uses
$HOME/.cache/swift-sh.
Swift Versions
swfit-sh v2 requires Swift 5.1. We had to drop support for Swift v4.2
because maintenance was just too tricky.
swift-sh uses the active tools version, (ie: xcode-select) or whichever
Swift is first in the PATH on Linux. It writes a manifest for the package
it will swift build with that tools-version. Thus Xcode 11.0 builds with Swift 5.1.
Dependencies build with the Swift versions they declare support for, provided
the active toolchain can do that (eg. Xcode 11.0 supports Swift 4.2 and above)
To declare a support for specific Swift versions in your script itself, use
#if swift or #if compiler directives.
Alternatives
Beak
Marathon
Troubleshooting
error: unable to invoke subcommand: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-sh
If you got here via Google, you have a script that uses this tool, if you now
install swift-sh, you will be able to run your script:
mxcl/swift-sh thuộc nhóm Mobile trên TopGit, cùng 2 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về mxcl/swift-sh ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/mxcl/swift-sh là nguồn chính thức.
mxcl/swift-sh có bao nhiêu sao?
mxcl/swift-sh có 1.9k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/mxcl/swift-sh. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
mxcl/swift-sh có phải mã nguồn mở không?
Có — mxcl/swift-sh phát hành theo license Unlicense, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/mxcl/swift-sh.
mxcl/swift-sh có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho mxcl/swift-sh. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
mxcl/swift-sh là gì?
mxcl/swift-sh (mxcl/swift-sh) là dự án Swift trên GitHub. Theo mô tả gốc: Easily script with third-party Swift dependencies.
mxcl/swift-sh so với các dự án Mobile khác thế nào?
mxcl/swift-sh được TopGit xếp vào nhóm Mobile, với 1.9k sao GitHub và viết bằng Swift. Xem trang chủ đề Mobile trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc swift-sh có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về swift-sh.