All Projects → JohnSundell → Shellout

JohnSundell / Shellout

Licence: mit
Easily run shell commands from a Swift script or command line tool

Programming Languages

swift
15916 projects
bash
514 projects

Projects that are alternatives of or similar to Shellout

Cabal Cli
Terminal client for Cabal, the p2p chat platform.
Stars: ✭ 479 (-15.37%)
Mutual labels:  command-line
Ncbi Genome Download
Scripts to download genomes from the NCBI FTP servers
Stars: ✭ 494 (-12.72%)
Mutual labels:  command-line
Shiori
Simple bookmark manager built with Go
Stars: ✭ 5,315 (+839.05%)
Mutual labels:  command-line
Kong
Kong is a command-line parser for Go
Stars: ✭ 481 (-15.02%)
Mutual labels:  command-line
Rtv
Browse Reddit from your terminal
Stars: ✭ 4,558 (+705.3%)
Mutual labels:  command-line
Telegram Send
Send messages and files over Telegram from the command-line.
Stars: ✭ 519 (-8.3%)
Mutual labels:  command-line
Instainsane
Multi-threaded Instagram Brute Forcer (100 attemps at once)
Stars: ✭ 475 (-16.08%)
Mutual labels:  command-line
Carbon Now Cli
🎨 Beautiful images of your code — from right inside your terminal.
Stars: ✭ 5,165 (+812.54%)
Mutual labels:  command-line
Wow
😮❗️❗️ Wow❗️ now my Go commandline app is spinning with 🌈 and 🐴
Stars: ✭ 494 (-12.72%)
Mutual labels:  command-line
Git Labelmaker
🎏 Manage your GitHub labels from the command line!
Stars: ✭ 534 (-5.65%)
Mutual labels:  command-line
Polyglot
A universal grpc command line client
Stars: ✭ 488 (-13.78%)
Mutual labels:  command-line
Xonsh
🐚 Python-powered, cross-platform, Unix-gazing shell
Stars: ✭ 5,327 (+841.17%)
Mutual labels:  command-line
Jrnl
Collect your thoughts and notes without leaving the command line.
Stars: ✭ 5,126 (+805.65%)
Mutual labels:  command-line
Quicli
Quickly build cool CLI apps in Rust.
Stars: ✭ 481 (-15.02%)
Mutual labels:  command-line
Tosheets
Send your stdin to google sheets
Stars: ✭ 536 (-5.3%)
Mutual labels:  command-line
Cz Conventional Changelog
A commitizen adapter for the angular preset of https://github.com/conventional-changelog/conventional-changelog
Stars: ✭ 477 (-15.72%)
Mutual labels:  command-line
Macports Base
The MacPorts command-line client
Stars: ✭ 502 (-11.31%)
Mutual labels:  command-line
Csvtk
A cross-platform, efficient and practical CSV/TSV toolkit in Golang
Stars: ✭ 566 (+0%)
Mutual labels:  command-line
Cli
A command-line interface for Hetzner Cloud
Stars: ✭ 542 (-4.24%)
Mutual labels:  command-line
Nve
Run any command on specific Node.js versions
Stars: ✭ 531 (-6.18%)
Mutual labels:  command-line

🐚 ShellOut

Welcome to ShellOut, a simple package that enables you to easily “shell out” from a Swift script or command line tool.

Even though you can accomplish most of the tasks you need to do in native Swift code, sometimes you need to invoke the power of the command line from a script or tool - and this is exactly what ShellOut makes so simple.

Usage

Just call shellOut(), and specify what command you want to run, along with any arguments you want to pass:

let output = try shellOut(to: "echo", arguments: ["Hello world"])
print(output) // Hello world

You can also easily run a series of commands at once, optionally at a given path:

try shellOut(to: ["mkdir NewFolder", "echo \"Hello again\" > NewFolder/File"], at: "~/CurrentFolder")
let output = try shellOut(to: "cat File", at: "~/CurrentFolder/NewFolder")
print(output) // Hello again

In case of an error, ShellOut will automatically read STDERR and format it nicely into a typed Swift error:

do {
    try shellOut(to: "totally-invalid")
} catch {
    let error = error as! ShellOutError
    print(error.message) // Prints STDERR
    print(error.output) // Prints STDOUT
}

Pre-defined commands

Another way to use ShellOut is by executing pre-defined commands, that enable you to easily perform common tasks without having to construct commands using strings. It also ships with a set of such pre-defined commands for common tasks, such as using Git, manipulating the file system and using tools like Marathon, CocoaPods and fastlane.

Use Git

try shellOut(to: .gitInit())
try shellOut(to: .gitClone(url: repositoryURL))
try shellOut(to: .gitCommit(message: "A scripted commit!"))
try shellOut(to: .gitPush())
try shellOut(to: .gitPull(remote: "origin", branch: "release"))
try shellOut(to: .gitSubmoduleUpdate())
try shellOut(to: .gitCheckout(branch: "my-feature"))

Handle files, folders and symlinks

try shellOut(to: .createFolder(named: "folder"))
try shellOut(to: .createFile(named: "file", contents: "Hello world"))
try shellOut(to: .moveFile(from: "path/a", to: "path/b"))
try shellOut(to: .copyFile(from: "path/a", to: "path/b"))
try shellOut(to: .openFile(at: "Project.xcodeproj"))
try shellOut(to: .readFile(at: "Podfile"))
try shellOut(to: .removeFile(from: "path/a"))
try shellOut(to: .createSymlink(to: "target", at: "link"))
try shellOut(to: .expandSymlink(at: "link"))

For a more powerful and object-oriented way to handle Files & Folders in Swift, check out Files

Use Marathon

try shellOut(to: .runMarathonScript(at: "~/scripts/MyScript", arguments: ["One", "Two"]))
try shellOut(to: .updateMarathonPackages())

Use The Swift Package Manager

try shellOut(to: .createSwiftPackage(withType: .executable))
try shellOut(to: .updateSwiftPackages())
try shellOut(to: .generateSwiftPackageXcodeProject())
try shellOut(to: .buildSwiftPackage())
try shellOut(to: .testSwiftPackage())

Use fastlane

try shellOut(to: .runFastlane(usingLane: "appstore"))

Use CocoaPods

try shellOut(to: .updateCocoaPods())
try shellOut(to: .installCocoaPods())

Don't see what you're looking for in the list above? You can easily define your own commands using ShellOutCommand. If you've made a command you think should be included among the built-in ones, feel free to open a PR!

Installation

For scripts

  • Install Marathon.
  • Add ShellOut to Marathon using $ marathon add https://github.com/JohnSundell/ShellOut.git.
  • Alternatively, add https://github.com/JohnSundell/ShellOut.git to your Marathonfile.
  • Write your script, then run it using $ marathon run yourScript.swift.

For command line tools

  • Add .package(url: "https://github.com/JohnSundell/ShellOut.git", from: "2.0.0") to your Package.swift file's dependencies.
  • Update your packages using $ swift package update.

Help, feedback or suggestions?

  • Open an issue if you need help, if you found a bug, or if you want to discuss a feature request.
  • Open a PR if you want to make some change to ShellOut.
  • Contact @johnsundell on Twitter for discussions, news & announcements about ShellOut & other projects.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].