Skip to content

Instantly share code, notes, and snippets.

@ivanopagano
Last active May 15, 2020 08:04
Show Gist options
  • Select an option

  • Save ivanopagano/fa7339916f833f6b7c8fd88f65cdebc1 to your computer and use it in GitHub Desktop.

Select an option

Save ivanopagano/fa7339916f833f6b7c8fd88f65cdebc1 to your computer and use it in GitHub Desktop.
Custom sbt prompt
//configure custom sbt prompt
ThisBuild / shellPrompt := { state =>
val extracted = Project.extract(state)
import extracted._
/* COLOR DEFS
* for ansi color codes refer to http://www.calmar.ws/vim/color-output.png
* and to https://misc.flogisoft.com/bash/tip_colors_and_formatting
*/
type Color = Byte
val fontFg = 15.toByte
val scalaBg = 9.toByte
val sbtBg = 6.toByte
val projectBg = 33.toByte
val separator = "\uE0B4"
val bg = (code: Color) => s"\u001b[48;5;${code}m"
val fg = (code: Color) => s"\u001b[38;5;${code}m"
val no_bg = "\u001b[49m"
val no_fg = "\u001b[39m"
/* SECTION DEFS */
def split(from: Color, to: Color) =
fg(from) :: bg(to) :: separator :: fg(fontFg) :: Nil
def end(from: Color) =
fg(from) :: no_bg :: separator :: no_fg :: " " :: Nil
def section(
background: Color,
content: List[String],
foreground: Color = fontFg
): List[String] =
bg(background) :: fg(foreground) :: content
/* CONTENT DEFS */
val scalaLogo = "\uE737"
val sbtLogo = "sbt"
val pad = " "
val module = {
val root = rootProject(currentRef.build)
val current = currentRef.project
if (root == current) current else s"[$root].$current"
}
val scalaV = scalaVersion.get(structure.data).getOrElse("")
val sbtV = sbtVersion.get(structure.data).fold("")("-" + _ )
val projectV = (currentRef / version).get(structure.data).fold("")("-" + _ )
/* BUILD THE BAR */
val scalaSection =
section(
scalaBg,
content = pad :: scalaLogo :: pad :: scalaV :: Nil
)
val sbtSection =
section(
sbtBg,
content = pad :: sbtLogo :: sbtV :: Nil
)
val projectSection =
section(
projectBg,
content = pad :: module :: projectV :: Nil
)
List.concat(
scalaSection
, split(from = scalaBg, to = sbtBg)
, section(sbtBg, pad :: "sbt" :: sbtV :: Nil)
, split(from = sbtBg, to = projectBg)
, section(projectBg, pad :: module :: projectV :: Nil)
, end(from = projectBg)
).mkString
}
@ivanopagano

Copy link
Copy Markdown
Author

Separator fonts are done with nerd fonts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment