- Create ~/.sbt/0.13/plugins folder if it doesn't exist yet
- Move 2 files to said plugins folder
- reload sbt console and witness your git prompt
Created
August 2, 2017 16:08
-
-
Save EdgeCaseBerg/fe1022ee3ad7e7608cc0e7b832988bea to your computer and use it in GitHub Desktop.
Make a git prompt in sbt!
This file contains hidden or 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
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 ("> ") | |
} | |
} |
This file contains hidden or 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
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