diff --git a/main/command/src/main/scala/sbt/MainLoop.scala b/main/command/src/main/scala/sbt/MainLoop.scala index 488decab0..c393be3f3 100644 --- a/main/command/src/main/scala/sbt/MainLoop.scala +++ b/main/command/src/main/scala/sbt/MainLoop.scala @@ -65,6 +65,13 @@ object MainLoop { val newLogging = state.globalLogging.newLogger(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 warn "Executing in batch mode." + state.log warn " For better performance, hit [ENTER] to switch to interactive mode, or" + state.log warn " consider launching sbt without any commands, or explicitly passing 'shell'" + } try run(loggedState) finally out.close() } diff --git a/main/command/src/main/scala/sbt/State.scala b/main/command/src/main/scala/sbt/State.scala index b7f38fbba..218e136af 100644 --- a/main/command/src/main/scala/sbt/State.scala +++ b/main/command/src/main/scala/sbt/State.scala @@ -176,13 +176,18 @@ object State { /** Provides operations and transformations on State. */ implicit def stateOps(s: State): StateOps = new StateOps { - def process(f: (String, State) => State): State = - s.remainingCommands match { - case Seq() => exit(true) - case Seq(x, xs @ _*) => - log.debug(s"> $x") - f(x, s.copy(remainingCommands = xs, history = x :: s.history)) + def process(f: (String, State) => State): State = { + def doX(x: String, xs: Seq[String]) = { + log.debug(s"> $x") + f(x, s.copy(remainingCommands = xs, history = x :: s.history)) } + def isInteractive = System.console() != null + def hasInput = System.console().reader().ready() + s.remainingCommands match { + case Seq() => if (isInteractive && hasInput) doX("shell", Nil) else exit(true) + case Seq(x, xs @ _*) => doX(x, xs) + } + } def :::(newCommands: Seq[String]): State = s.copy(remainingCommands = newCommands ++ s.remainingCommands) def ::(command: String): State = (command :: Nil) ::: this def ++(newCommands: Seq[Command]): State = s.copy(definedCommands = (s.definedCommands ++ newCommands).distinct) 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