Re: [sbt] How to color ShellPrompt

259 views
Skip to first unread message

wookietreiber

unread,
Dec 16, 2012, 2:43:36 PM12/16/12
to simple-b...@googlegroups.com
Hello Anthony,

First few lines from my ~/.sbt/global.sbt

1
2 shellPrompt := { state ⇒
3 (scala.Console.CYAN + "sbt @ %s > " + scala.Console.RESET) format {
4 Project.extract(state).getOpt(sbt.Keys.name) getOrElse {
5 Project.extract(state).currentProject.id
6 }
7 }
8 }
9

Have a look at the scala.Console$ documentation for other supported
colors:

http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/library/index.html#scala.Console$

The other part of my shell prompt is the name or else the id of the
current project.


On Sat, Dec 15, 2012 at 04:19:26PM -0800, Anthony wrote:
> When creating a custom prompt, such as the docs example below, is it possible
> to color the prompt similar to escape codes in .bashrc?
>
> I'm using sbt 0.12.1 and Ubuntu 12.04.
>
> I don't have a lot of linux experience so I appreciate a specific reference or
> example.
>
> object ShellPrompt {
> object devnull extends ProcessLogger {
> def info (s: => String) {}
> def error (s: => String) { }
> def buffer[T] (f: => T): T = f
> }
> def currBranch = (
> ("git status -sb" lines_! devnull headOption)
> getOrElse "-" stripPrefix "## "
> )
>
> val buildShellPrompt = {
> (state: State) => {
> val currProject = Project.extract (state).currentProject.id
> "%s:%s:%s> ".format (
> currProject, currBranch, VersionSettings.buildVersion
> )
> }
> }
> }
>
> --Anthony
>
> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/
> simple-build-tool/-/lMa2aVgCa3gJ.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to
> simple-build-t...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/
> simple-build-tool?hl=en.

--

Beste Grüße / Best Regards
Christian Krause aka wookietreiber

-----------------------------------------------------------------------

EGAL WIE DICHT DU BIST, GOETHE WAR DICHTER.

Anthony

unread,
Dec 17, 2012, 11:21:56 AM12/17/12
to simple-b...@googlegroups.com, wookietreiber
Thanks Christian! That was super helpful. Below is where I've ended up for now, thanks to your help.

Now I'm off to see if I can handle https://github.com/harrah/xsbt/issues/625#issuecomment-11424656. I love me some multi-line prompts for any cli that I spend decent time in.

shellPrompt := { state ⇒

  object devnull extends ProcessLogger {
    def info (s: => String) {}
    def error (s: => String) { }
    def buffer[T] (f: => T): T = f
  }
  val currBranch = (

    ("git status -sb" lines_! devnull headOption)
      getOrElse "-" stripPrefix "## "
  )
  val p = Project.extract(state)
  val projectNameOrId = p.getOpt(sbt.Keys.name) getOrElse { p.currentProject.id }
  val projectVersion = p.getOpt(sbt.Keys.version) getOrElse { "" }
  import scala.Console.RESET
  val LYELLOW="\033[1;33m"
  val LGREEN="\033[1;32m"
  val LBLUE="\033[01;34m"
  ("%s%s%s:%s%s%s:%s%s%s> ").format(
    LGREEN, projectNameOrId, RESET,
    LBLUE, projectVersion, RESET,
    LYELLOW,currBranch, RESET)
}

--Anthony
Reply all
Reply to author
Forward
0 new messages