Last active
November 21, 2015 06:43
-
-
Save pedrofurla/d26b2ba7be52c3b178da to your computer and use it in GitHub Desktop.
Nice looks and git info into the sbt shell
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
| addCommandAlias("git", "; sh git") | |
| commands ++= Seq( | |
| Command.args("sh", "<shell command>") { (state, args) => | |
| // using script here maintains ansi colors, see http://stackoverflow.com/a/13587964/467390 | |
| val ret = ("script -q /dev/null " ++ args.mkString(" ")) !; | |
| state | |
| } | |
| ) | |
| shellPrompt := { state => | |
| val oldErr = System.err | |
| val extracted = Project.extract(state) | |
| val project = extracted.currentRef.project; | |
| object bg{ | |
| val blue = "\u001B[44m" | |
| val magenta = "\u001B[45m" | |
| val green = "\u001B[42m" | |
| val white = "\u001B[47m" | |
| } | |
| object fg{ | |
| val black = "\u001B[30m" | |
| val blue = "\u001B[34m" | |
| val green = "\u001B[32m" | |
| val white = "\u001B[37m" | |
| val magenta = "\u001B[35m" | |
| } | |
| val reset = "\u001B[0m" | |
| val sep = "\uE0B0" | |
| import java.io.{OutputStream, PrintStream} | |
| class VoidOutputStream extends OutputStream { | |
| override def write(b: Int) = () | |
| override def write(b: Array[Byte]) = () | |
| override def write(b: Array[Byte], off: Int, len: Int) = () | |
| } | |
| val nullStream = new PrintStream(new VoidOutputStream()) | |
| System.setOut(nullStream) | |
| System.setErr(nullStream) | |
| val branchOrSeparator = try{ | |
| val branch = "git rev-parse --abbrev-ref HEAD".split(" ").toSeq.!!.replace(System.lineSeparator, "") | |
| val modified = "git status -s --ignore-submodules=dirty".split(" ").toSeq.!!.nonEmpty | |
| val (bgColor, fgColor)= if(modified) (bg.magenta, fg.magenta) else (bg.green, fg.green) | |
| val modifiedSymbol = if(modified) "±" else "" | |
| bgColor ++ fg.blue ++ sep ++ " " ++ fg.black ++ "" ++ branch ++ " " ++ modifiedSymbol ++ bg.white ++ fgColor | |
| } catch { | |
| case e:java.lang.RuntimeException => | |
| bg.white ++ fg.blue | |
| } finally { | |
| System.setErr(oldErr) | |
| System.setOut(oldErr) | |
| } | |
| ( | |
| fg.black ++ bg.blue | |
| ++ project | |
| ++ branchOrSeparator | |
| ++ sep ++ " " ++ fg.black ++ "sbt" | |
| ++ reset ++ fg.white ++ sep ++ reset | |
| ++ " " | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment