diff --git a/main-command/src/main/scala/sbt/State.scala b/main-command/src/main/scala/sbt/State.scala index 11d0de3eb..8141d6f52 100644 --- a/main-command/src/main/scala/sbt/State.scala +++ b/main-command/src/main/scala/sbt/State.scala @@ -196,7 +196,18 @@ object State { /** Provides operations and transformations on State. */ implicit def stateOps(s: State): StateOps = new StateOps { - def process(f: (Exec, State) => State): State = + def process(f: (Exec, State) => State): State = { + def doX(x: Exec, xs: List[Exec]) = { + log.debug(s"> $x") + f(x, s.copy(remainingCommands = xs, currentCommand = Some(x), history = x :: s.history)) + } + def isInteractive = System.console() != null + def hasInput = System.console().reader().ready() + s.remainingCommands match { + case List() => if (isInteractive && hasInput) doX(Exec("shell", s.source), Nil) else exit(true) + case List(x, xs @ _*) => doX(x, xs) + } + } s.remainingCommands match { case List() => exit(true) case x :: xs => diff --git a/main/src/main/scala/sbt/MainLoop.scala b/main/src/main/scala/sbt/MainLoop.scala index f269d571e..5b45055e1 100644 --- a/main/src/main/scala/sbt/MainLoop.scala +++ b/main/src/main/scala/sbt/MainLoop.scala @@ -72,6 +72,10 @@ object MainLoop { val newLogging = state.globalLogging.newAppender(full, out, logBacking) // transferLevels(state, newLogging) val loggedState = state.copy(globalLogging = newLogging) + def isInteractive = System.console() != null + def hasShell = state.remainingCommands contains "shell" + if (isInteractive && !hasShell) + state.log info "!!! Executing in batch mode !!! For better performance, hit [ENTER] to remain in the sbt shell" try run(loggedState) finally out.close() } diff --git a/notes/0.13.14/stay-in-shell.md b/notes/0.13.14/stay-in-shell.md new file mode 100644 index 000000000..be4c7f956 --- /dev/null +++ b/notes/0.13.14/stay-in-shell.md @@ -0,0 +1,7 @@ +### Improvements + +- Notifies & enables users to stay in sbt's shell on the warm JVM by hitting \[ENTER\] while sbt is running. [#2987][]/[#2996][] by [@dwijnand][] + +[#2987]: https://github.com/sbt/sbt/issues/2987 +[#2996]: https://github.com/sbt/sbt/pull/2996 +[@dwijnand]: https://github.com/dwijnand