Skip to content

Instantly share code, notes, and snippets.

@gseitz
Created July 23, 2011 15:58
Show Gist options
  • Save gseitz/1101576 to your computer and use it in GitHub Desktop.
Save gseitz/1101576 to your computer and use it in GitHub Desktop.
SBT shell prompt respecting -Dsbt.nologformat
import sbt._
import Keys._
// source of the actual shell modification take from Daniel C. Sobral's gist:
// https://gist.github.com/996474
// prompt looks like:
// $PROJECTNAME:$GITBRANCH>
object ShellPrompt extends Plugin {
object devnull extends ProcessLogger {
def info(s: => String) {}
def error(s: => String) { }
def buffer[T](f: => T): T = f
}
val current = """\*\s+(\w+)""".r
def gitBranches = ("git branch --no-color" lines_! devnull mkString)
def prompt(name: String) =
"%s:%s> " format (name,
current findFirstMatchIn gitBranches map (_.group(1)) getOrElse "-"
)
override def settings: Seq[Setting[_]] =
if (System.getProperty("sbt.nologformat", "false") != "true")
Seq[Setting[_]](
shellPrompt <<= name(name => { state: State => prompt(name) })
)
else
Seq()
}
// vim: set ts=4 sw=4 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment