GithubHelp home page GithubHelp logo

sbt-sh's Introduction

sbt-sh

Using the sbt-sh plugin you can invoke shell commands:

root> sh git status
[info] On branch wip/sequential
[info] Your branch is up-to-date with 'upstream/wip/sequential'.
[info] nothing to commit, working directory clean

Happiness and productivity ensues without the hassle of exiting sbt or opening multiple terminals.

Setup

Requirements:

  • sbt 0.13.7+

To install sbt-sh, add it to your global sbt plugin list by creating ~/.sbt/0.13/plugins/sh.sbt:

addSbtPlugin("com.eed3si9n" % "sbt-sh" % "0.1.0")

Usage

The sbt-sh plugin introduces the sh task to sbt. This will execute the rest of the line as a shell command:

sbt-sh> sh ls
[info] LICENSE
[info] README.markdown
[info] build.sbt
[info] project
[info] src
[info] target
[success] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM

sh is an input task that returns Seq[String] containing each line from the output.

sbt-sh> show sh ls
[info] LICENSE
[info] README.markdown
[info] build.sbt
[info] project
[info] src
[info] target
[info] List(LICENSE, README.markdown, build.sbt, project, src, target)
[success] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM

Pipeline supported is limited to one level:

sbt-sh> sh ag case src | wc -l
[info]       34
[success] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM
sbt-sh> sh find . -iname *.scala | xargs cat | wc -l
[error] ({.}/*:sh) java.lang.IllegalArgumentException: requirement failed: Piping to multiple processes is not supported.
[error] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM

Redirect assumes rhs is a file:

sbt-sh> sh ls > ls.txt
[success] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM
sbt-sh> sh cat < ls.txt
[info] LICENSE
[info] README.markdown
[info] build.sbt
[info] ls.txt
[info] project
[info] src
[info] target
[success] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM

Logical operators work:

sbt-sh> sh cat nonexistent.txt || cat ls.txt | wc -l
[error] cat: nonexistent.txt: No such file or directory
[info]        7
[success] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM
sbt-sh> sh cat nonexistent.txt && cat ls.txt | wc -l
[error] cat: nonexistent.txt: No such file or directory
[error] Nonzero exit code: 1
[error] ({.}/*:sh) Nonzero exit code: 1
[error] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM

Background process works only at the top level:

sbt-sh> sh (subl . & ls | wc -l &)
[error] Expected '&&'
[error] sh (subl . & ls | wc -l &)
[error]             ^
sbt-sh> sh (subl .; ls | wc -l;) &
[success] Total time: 0 s, completed Jan 23, 2015 11:00:00 PM
       7

In Sublime Text pops up in the background, and it prints out 7 on shell.

Credits

  • On 2009-09-12, @harrah released sbt 0.5.4, which mentions "sh task for users with a unix-style shell." It uses /bin/sh -c. Current releases of sbt no longer supports sh or exec.
  • On 2011-07-09, @steppenwells wrote the original steppenwells/sbt-sbt, which adds sh task that simply forks commands as args.mkString(" ") ! like exec.
  • On 2015-01-24, @eed3si9n rewrote sbt-sbt, emulating POSIX shell-like features using sbt's parser combinator and sbt.Process API.

sbt-sh's People

Contributors

eed3si9n avatar steppenwells avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.