Skip to content

Instantly share code, notes, and snippets.

@EdgeCaseBerg
Created August 2, 2017 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdgeCaseBerg/fe1022ee3ad7e7608cc0e7b832988bea to your computer and use it in GitHub Desktop.
Save EdgeCaseBerg/fe1022ee3ad7e7608cc0e7b832988bea to your computer and use it in GitHub Desktop.
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