Skip to content

Instantly share code, notes, and snippets.

@patmandenver
Last active March 29, 2016 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmandenver/0ff2df21755bd0bde89e to your computer and use it in GitHub Desktop.
Save patmandenver/0ff2df21755bd0bde89e to your computer and use it in GitHub Desktop.
Final build.sbt with unicode similar to powerline font
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 =>
//Special Characters
val branch = "\uE0A0"
val lock = "\uE0A2"
val rArrow = "\uE0B0"
val lArrow = "\uE0B2"
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(rArrow)(orange, yellow) +
formatText(s" $branch $gitBranch ")(black, yellow) +
formatText(rArrow)(yellow, black) +
"\n " +
formatText("\u276f\u276f\u276f ")(orange, black)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment