Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup SBT from bash from IntelliJ IDEA to avoid formatting characters being broken?

When running on Windows, I have changed my default terminal in the IntelliJ IDE from default Windows cmd to bash (I am using the one installed with Git, located at C:\Program Files\Git\bin\bash.exe). It works very well, the only trouble is that when running sbt from the terminal, some strange characters are shown (I assume they are some control characters intended to format the output).

This does not happen when I run sbt directly from the bash launched in the Windows as a standalone window.

Is there some setting (an environment variable or a config file) for any of the three components involved (sbt, IntelliJ, bash) I could change so that I do not see those formatting characters misinterpreted? If they would work and affect the formatting it would be a nice bonus, but that is less important to me.

IntelliJ:

IntelliJ

Standalone:

Standalone

like image 265
Suma Avatar asked Feb 03 '26 10:02

Suma


2 Answers

sbt by default colors the console output, which does not work on Windows, but perhaps the launcher script doesn't disable the codes in the IntelliJ terminal script.

You can disable colors by passing the -Dsbt.log.noformat=true to sbt

like image 186
Justin Kaeser Avatar answered Feb 05 '26 05:02

Justin Kaeser


You can preserve the colours and formatting if you add the following to your .bashrc file:

sbt() {
    /c/progra~2/sbt/bin/sbt.bat "$@"
}
export -f sbt

.bashrc can be found (or created) in your %USERPROFILE% directory, e.g. C:\Users\{username}\.bashrc.

Substitute a different path to sbt.bat if necessary, but it needs to be without spaces.

Restart your terminal afterwards, or run source ~/.bashrc.

This exports a bash function that causes "sbt" to run the sbt batch file launcher instead of the shell script launcher that it would otherwise. The batch launcher clearly does a better job of processing the output on Windows. (I also use this for gcloud and gsutil commands that fall over in other ways when invoked from Bash.)

like image 42
Martin Stone Avatar answered Feb 05 '26 05:02

Martin Stone