Created
July 23, 2011 15:58
-
-
Save gseitz/1101576 to your computer and use it in GitHub Desktop.
SBT shell prompt respecting -Dsbt.nologformat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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