Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import sbt._
  2. import Keys._
  3.  
  4.  
  5. // source of the actual shell modification take from Daniel C. Sobral's gist:
  6. // https://gist.github.com/996474
  7.  
  8. // prompt looks like:
  9. // $PROJECTNAME:$GITBRANCH>
  10. object ShellPrompt extends Plugin {
  11.   object devnull extends ProcessLogger {
  12.     def info(s: => String) {}
  13.     def error(s: => String) { }
  14.     def buffer[T](f: => T): T = f
  15.   }
  16.   val current = """\*\s+(\w+)""".r
  17.   def gitBranches = ("git branch --no-color" lines_! devnull mkString)
  18.  
  19.   def prompt(name: String) =
  20.     "%s:%s> " format (name,
  21.       current findFirstMatchIn gitBranches map (_.group(1)) getOrElse "-"
  22.     )
  23.  
  24.   override def settings: Seq[Setting[_]] =
  25.     if (System.getProperty("sbt.nologformat", "false") != "true")
  26.       Seq[Setting[_]](
  27.         shellPrompt <<= name(name => { state: State => prompt(name) })
  28.       )
  29.     else
  30.       Seq()
  31. }
  32.  
  33. // vim: set ts=4 sw=4 et: