Created
March 25, 2016 21:16
-
-
Save patmandenver/db4f53cb80b662ca7522 to your computer and use it in GitHub Desktop.
global build.sbt with git branch but no special unicode
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 java.io.{ByteArrayOutputStream, PrintWriter} | |
| import sbt.{ProcessBuilder, ProcessLogger} | |
| def runCommand(cmd: Seq[String]): (Int, String, String) = { | |
| val stdout = new ByteArrayOutputStream | |
| val stderr = new ByteArrayOutputStream | |
| val stdoutWriter = new PrintWriter(stdout) | |
| val stderrWriter = new PrintWriter(stderr) | |
| val exitValue = cmd.!(new ProcessLogger { | |
| def info (s: => String) { stdoutWriter.print(s) } | |
| def error (s: => String) { stderrWriter.print(s) } | |
| def buffer[T] (f: => T): T = f | |
| }) | |
| stdoutWriter.close() | |
| stderrWriter.close() | |
| (exitValue, stdout.toString, stderr.toString) | |
| } | |
| def gitBranch = { | |
| runCommand("git rev-parse --abbrev-ref HEAD".split(" ").toSeq) match { | |
| case (exit, _, _) if(exit != 0) => "No-Git" | |
| case (_, stdout, _) => stdout | |
| } | |
| } | |
| shellPrompt := { state => | |
| def textColor(color: Int) = { s"\033[38;5;${color}m" } | |
| def backgroundColor(color:Int) = { s"\033[48;5;${color}m" } | |
| def reset = { s"\033[0m" } | |
| def formatText(str: String)(txtColor: Int, backColor: Int) = { | |
| s"${textColor(txtColor)}${backgroundColor(backColor)}${str}${reset}" | |
| } | |
| val red = 1 | |
| val green = 2 | |
| val yellow = 11 | |
| val white = 15 | |
| val black = 16 | |
| val orange = 166 | |
| formatText(s"[${name.value}]")(white, orange) + | |
| formatText(s" $gitBranch ")(black, yellow) + | |
| "\n " + | |
| formatText(">>> ")(orange, black) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment