Skip to content

Instantly share code, notes, and snippets.

@ssanj
Last active October 24, 2018 16:11
Show Gist options
  • Save ssanj/0ecd4a9670f204e9b5c2e5dce31f3d0f to your computer and use it in GitHub Desktop.
Save ssanj/0ecd4a9670f204e9b5c2e5dce31f3d0f to your computer and use it in GitHub Desktop.
//put in ~/.sbt/1.0/global.sbt if you want this to be the default shell everywhere
import scala.sys.process._
import scala.util.Try
shellPrompt := { s: State =>
val extracted = Project.extract(s)
val devNull = ProcessLogger(_ => ())
val branchOp: Option[String] = Try(sys.process.Process("git rev-parse --abbrev-ref HEAD").!!(devNull)).
map(_.replace("\n", "").replace("\r", "")).
toOption
(name in extracted.currentRef).get(extracted.structure.data) match {
case Some(name) =>
branchOp.fold(s"${RESET}${CYAN}${name}${RESET}> ")(branch =>
s"${RESET}${CYAN}${name}${RESET}:${RESET}${YELLOW}${BOLD}${branch}${RESET}> ")
case _ => "> "
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment