Last active
August 29, 2015 13:56
-
-
Save ppurang/9247136 to your computer and use it in GitHub Desktop.
sbt prompt with git branch and git status for modifications etc.
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
// the following results in | |
// superduperproject : master : 0.1.0 : MD??> | |
// where M => Modified, D => Deleted, ?? => not tracked | |
// and might include (not tested :)) | |
// !, R, C, U for details check https://www.kernel.org/pub/software/scm/git/docs/git-status.html#_short_format | |
// if you see superduperproject : master : 0.1.0 : -?-> ... well then oops and happy debugging and do tell... | |
shellPrompt in ThisBuild := ShellPrompt.buildShellPrompt("0.1.0") |
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 0.13+ | |
// how often a prompt gets updated? can't tell | |
// lifted from http://www.scala-sbt.org/release/docs/Examples/Full-Configuration-Example.html and modified | |
object ShellPrompt { | |
object devnull extends ProcessLogger { | |
def info (s: => String) {} | |
def error (s: => String) { } | |
def buffer[T] (f: => T): T = f | |
} | |
val oops = "-?-" | |
def currBranch = ("git branch" lines_! devnull headOption) getOrElse oops stripPrefix "* " | |
def currModifications = ("git status -sb" lines_! devnull tail).foldLeft("")( | |
(a,n) =>n.trim.split(" ").headOption.map(m => if(a.contains(m)) a else a + m) getOrElse oops | |
) // can do better? | |
def buildShellPrompt(ver: String) = { | |
(state: State) => { | |
val currProject = Project.extract (state).currentProject.id | |
"%s : %s : %s : %s> ".format ( | |
currProject, currBranch, ver, currModifications | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment