Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make a git prompt in sbt!
  1. Create ~/.sbt/0.13/plugins folder if it doesn't exist yet
  2. Move 2 files to said plugins folder
  3. reload sbt console and witness your git prompt
import sbt._
import Keys._
// This lifted from https://github.com/mingchuno/aws-wrap/blob/master/project/CustomShellPrompt.scala
object CustomShellPrompt {
val Branch = """refs/heads/(.*)\s""".r
def gitBranchOrSha =
(Process("git symbolic-ref HEAD") #|| Process("git rev-parse --short HEAD")).!! match {
case Branch(name) => name
case sha => sha.stripLineEnd
}
val customPrompt = { state: State =>
val extracted = Project.extract(state)
import extracted._
(name in currentRef get structure.data) map { name =>
"[" + scala.Console.CYAN + name + scala.Console.RESET + "] " +
scala.Console.BLUE + "git:(" +
scala.Console.RED + gitBranchOrSha +
scala.Console.BLUE + ")" +
scala.Console.RESET + " $ "
} getOrElse ("> ")
}
}
import sbt._
import Keys._
object ShellPrompt extends Plugin {
override def settings = Seq(
shellPrompt := CustomShellPrompt.customPrompt
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment