Created
March 20, 2016 13:29
-
-
Save patmandenver/71839aaf63c71f4d6cd2 to your computer and use it in GitHub Desktop.
~/.sbt/0.13/global.sbt
This file contains 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
/* | |
* | |
* sbt global sets shellPrompt | |
* Requires font that contains special Unicode Characters | |
* | |
* U+276f | |
* (powerline compatibile) | |
* U+E0A0 (gt branch symbol) | |
* U+E0A2 (padlock symbol) | |
* U+E0B0 (Right Arrow) | |
* U+E0B2 (Left Arrow) | |
* | |
*The MIT License (MIT) | |
* | |
*Copyright (c) 2015 "whiteboardcoder" Patrick Bailey | |
* | |
*Permission is hereby granted, free of charge, to any person obtaining a copy | |
*of this software and associated documentation files (the "Software"), to deal | |
*in the Software without restriction, including without limitation the rights | |
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
*copies of the Software, and to permit persons to whom the Software is | |
*furnished to do so, subject to the following conditions: | |
* | |
*The above copyright notice and this permission notice shall be included in all | |
*copies or substantial portions of the Software. | |
* | |
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
*SOFTWARE. | |
* | |
*/ | |
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")(orange, black) + | |
formatText("\u276f")(orange, black) + | |
formatText("\u276f ")(orange, black) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment