From the URL I linked to, “fish is a fully-equipped command line shell (like bash or zsh) that is smart and user-friendly. fish supports powerful features like syntax highlighting, autosuggestions, and tab completions that just work, with nothing to learn or configure.”
Answer: Use the
consoleQuick commands inside the SBT shell:
consoleto start a REPL session from inside SBT. This (a) compiles your Scala project and then (b) starts a REPL session.
consoleQuickif you don’t want to compile your project before starting a REPL session inside of SBT.
console command process looks like this:
> sbt [info] Loading project definition from /Users/al/Projects/Cats101/project [info] Set current project to Cats101 (in build file:/Users/al/Projects/Cats101/) > console [info] Starting scala interpreter... [info] Welcome to Scala 2.12.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131). Type in expressions for evaluation. Or try :help. scala> _
If you wanted to see how to start a Scala REPL session from inside SBT, I hope this helps.
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.4" % "test"
it’s only available in the SBT “test” scope. This means that when you start a Scala REPL session inside of SBT with its
console command, the ScalaCheck library won’t be available in that scope.
To use ScalaCheck with the SBT console (REPL), don’t use its
console command — use
test:console instead. A complete example looks like this:
$ sbt > test:console scala> import org.scalacheck.Gen.choose
Note that after you type
test:console your project may be compiled, so that step may take a few moments.
In summary, use SBT’s
console command to start a “normal” Scala REPL inside SBT, and use
test:console to start a REPL that you can run tests inside of. (Note that this same advice also applies to using ScalaTest or specs2.)
To run external shell commands in SBT, first start SBT from your operating system command line:
Then run the
After some output you’ll see this prompt:
Now you can execute shell commands by including them in double quotes, and following them by an exclamation mark, like this:
scala> "ls -al" !
For more information, see the SBT consoleProject documentation page.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.4, “How to run a shell command from the Scala REPL.”
You want to be able to run a shell command from within the Scala REPL, such as listing the files in the current directory.
Run the command using the
:sh REPL command, then print the output. The following example shows how to run the Unix
ls -al command from within the REPL, and then show the results of the command:
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 14.13, “How to make your Scala shell scripts run faster by pre-compiling them.”
You love using Scala as a scripting language, but you’d like to eliminate the lag time in starting up a script.
-savecompiled argument of the Scala interpreter to save a compiled version of your script.
A basic Scala script like this:
This is an excerpt from the Scala Cookbook, partially modified for the internet. This is Recipe 14.12, “How to prompt users for input from Scala shell scripts.”Back to top
You want to prompt a user for input from a Scala shell script and read her responses.Back to top
Console.read* methods to read user input, as demonstrated in the following script. Comments in the script describe each method:
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.10, “How to use Scala as a scripting language.”Back to top
You want to use Scala as a scripting language on Unix systems, replacing other scripts you’ve written in a Unix shell (Bourne Shell, Bash), Perl, PHP, Ruby, etc.Back to top
Save your Scala code to a text file, making sure the first three lines of the script contain the lines shown, which will execute the script using the
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.1, “How to get started with the Scala REPL.”Back to top
You want to get started using the Scala REPL, including understanding some of its basic features, such as tab completion, starting the REPL with different options, and dealing with errors.Back to top
To start the Scala REPL, type
scala at your operating system command line:
As an Android developer, you can normally use the
adb push command to copy files from your computer’s hard drive to an Android device. However, I just ran into a problem where I couldn’t copy files to my Android emulator’s “data” directory, i.e., the /data/data filesystem. When I tried to copy a file using this command:
$ adb push foo.jpg /data/data/com.alvinalexander.myapp/files
I got this Android error: