All Projects → lordcodes → turtle

lordcodes / turtle

Licence: Apache-2.0 license
Run shell commands from a Kotlin script or application with ease

Programming Languages

kotlin
9241 projects

Labels

Projects that are alternatives of or similar to turtle

scalecube-config
ScaleCube Config is a configuration access management library for JVM based distributed applications
Stars: ✭ 15 (-88.28%)
Mutual labels:  jvm
play-java-rest-api-example
REST API using Play in Java
Stars: ✭ 44 (-65.62%)
Mutual labels:  jvm
generator-jvm
Generate JVM (java, kotlin, scala) project with gradle / maven / sbt build systems and docker / docker-compose for rapid development
Stars: ✭ 40 (-68.75%)
Mutual labels:  jvm
play-scala-seed.g8
Play Scala Seed Template: run "sbt new playframework/play-scala-seed.g8"
Stars: ✭ 66 (-48.44%)
Mutual labels:  jvm
jni-bind
JNI Bind is a set of advanced syntactic sugar for writing efficient correct JNI Code in C++17 (and up).
Stars: ✭ 42 (-67.19%)
Mutual labels:  jvm
mini-jvm
Go语言实现的JVM,实现了部分字节码的解释执行,学习JVM使用
Stars: ✭ 29 (-77.34%)
Mutual labels:  jvm
xoom-cluster
The VLINGO XOOM platform SDK cluster management for Reactive, scalable resiliency of JVM tools and applications running on XOOM LATTICE and XOOM ACTORS.
Stars: ✭ 25 (-80.47%)
Mutual labels:  jvm
jvm-dump-proxy
A proxy DLL for Windows to dump JVM classes at JNI level
Stars: ✭ 53 (-58.59%)
Mutual labels:  jvm
hello-kotlin-multiplatform
Multiplatform Kotlin Hello World (Android/Java/JavaScript)
Stars: ✭ 64 (-50%)
Mutual labels:  jvm
library-template-jvm
A Kotlin/JVM library template (with a sample project).
Stars: ✭ 46 (-64.06%)
Mutual labels:  jvm
etebase-java
A Java/Android client library for Etebase
Stars: ✭ 46 (-64.06%)
Mutual labels:  jvm
imgui-java
JNI based binding for Dear ImGui
Stars: ✭ 270 (+110.94%)
Mutual labels:  jvm
ark-java
Library for interacting with an Ark Ecosystem Blockchain using the JVM.
Stars: ✭ 15 (-88.28%)
Mutual labels:  jvm
hsbeat
Beat for Java HotSpot VM
Stars: ✭ 24 (-81.25%)
Mutual labels:  jvm
Latte-lang
100% Java compatibility and Functional Programming.
Stars: ✭ 128 (+0%)
Mutual labels:  jvm
jvmBASIC
A BASIC to JVM bytecode compiler
Stars: ✭ 40 (-68.75%)
Mutual labels:  jvm
Java-CS-Record
记录准备春招实习过程中,学习与复习的知识(模块化整理,非面试题速成)。注:暂停更新,后续请移步博客
Stars: ✭ 73 (-42.97%)
Mutual labels:  jvm
2p-kt
A Kotlin Multi-Platform ecosystem for symbolic AI
Stars: ✭ 52 (-59.37%)
Mutual labels:  jvm
pikt
🎨 Image-based poetic programming language.
Stars: ✭ 72 (-43.75%)
Mutual labels:  jvm
rake
A Java library for Rapid Automatic Keyword Extraction (RAKE) 🍂
Stars: ✭ 23 (-82.03%)
Mutual labels:  jvm

Turtle

Pure Kotlin Latest release Gradle build status Twitter: @lordcodes


Run shell commands from a Kotlin script or application with ease.

Turtle simplifies the process of running external commands and processes from your Kotlin (or Java) code. It comes bundled with a selection of built-in functions, such as opening MacOS applications and dealing with Git. Running shell commands easily is particularly useful from within Kotlin scripts, command line applications and Gradle tasks.

 

FeaturesInstallUsageContributing

Features

▶︎ Run shell commands with minimal boilerplate

Simply specify the comamnd and its arguments to easily run and retrieve output.

▶︎ Call any of the built-in shell commands

Various commands are provided, such as creating a Git commit and opening files.

▶︎ Use the function syntax to run a series of commands

Specify a sequence of commands to run within a function block.

▶︎ Capture error exit code and output

When a command produces an error, the exit code and error output is thrown as an exception.

Install

Turtle is provided as a Gradle/Maven dependency.

  • v0.5.0 onwards are available via Maven Central.
  • v0.3.0 and v0.4.0 had issues, so please use v0.5.0 or later.
  • Earlier releases were available via Bintray/JCenter.

▶︎ Gradle Kotlin DSL

dependencies {
  implementation("com.lordcodes.turtle:turtle:0.7.0")
}

▶︎ Gradle Groovy DSL

dependencies {
  implementation 'com.lordcodes.turtle:turtle:0.7.0'
}

Usage

To run a single custom command, just call shellRun() and provide the command and arguments.

val output = shellRun("git", listOf("rev-parse", "--abbrev-ref", "HEAD"))
println(output) // Current branch name, e.g. master

The working directory can be provided, to run the command in a particular location. ShellLocation provides easy access to some useful locations, such as the user's home directory.

val turtleProject = ShellLocation.HOME.resolve("projects/turtle")
val output = shellRun("git", listOf("rev-parse", "--abbrev-ref", "HEAD"), turtleProject)
println(output) // Current branch name, e.g. master

To run a series of commands or use the built-in commands, just call shellRun {}.

shellRun {
  command("mkdir tortoise")

  changeWorkingDirectory("tortoise")

  git.commit("Initial commit")
  git.addTag("v1.2", "Release v1.2")

  files.openApplication("Spotify")
}

The initial working directory can be specified.

val turtleProject = ShellLocation.HOME.resolve("projects/turtle")
shellRun(turtleProject) {
  …
}

Built-in commands

▶︎ Git

shellRun {
  git.init()
  git.status()
  git.commit("Commit message")
  git.commitAllChanges("Commit message")
  git.push("origin", "master")
  git.pull()
  git.checkout("release")
  git.clone("https://github.com/lordcodes/turtle.git")
  git.addTag("v1.1", "Release v1.1")
  git.pushTag("v1.1")
  git.currentBranch()
}

▶︎ Files

shellRun {
  files.openFile("script.kts")
  files.openApplication("Mail")
  files.createSymlink("target", "link")
  files.readSymlink("link")
}

▶︎ More

Extra commands can easily be added by either calling command or by extending ShellScript. If you have created a command that you think should be built in, please feel free to open a PR.

Contributing or Help

If you notice any bugs or have a new feature to suggest, please check out the contributing guide. If you want to make changes, please make sure to discuss anything big before putting in the effort of creating the PR.

To reach out, please contact @lordcodes on Twitter.

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].