Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class ScalaCliBase extends CommandsEntryPoint {

def actualDefaultCommand: DefaultBase

lazy val progName = (new Argv0).get("scala")
lazy val progName = (new Argv0).get("scala-cli")
override def description = "Compile, run, package Scala code."
final override def defaultCommand = Some(actualDefaultCommand)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.Arrays
import caseapp._
import caseapp.core.complete.{Bash, Zsh}

import scala.cli.internal.ProfileFileUpdater
import scala.cli.internal.{Argv0, ProfileFileUpdater}

object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
override def names = List(
Expand All @@ -23,6 +23,13 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {

val logger = options.logging.logger

val name = options.name.getOrElse {
val baseName = (new Argv0).get("scala-cli")
val idx = baseName.lastIndexOf(File.pathSeparator)
if (idx < 0) baseName
else baseName.drop(idx + 1)
}

val format = options.format.map(_.trim).filter(_.nonEmpty)
.orElse {
Option(System.getenv("SHELL")).map(_.split(File.separator).last).map {
Expand All @@ -31,21 +38,26 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
case other => other
}
}
.getOrElse(sys.error("Cannot determine current shell, pass the shell you use with --format"))
.getOrElse {
System.err.println("Cannot determine current shell, pass the shell you use with --shell, like")
System.err.println(s" $name install completions --shell zsh")
System.err.println(s" $name install completions --shell bash")
sys.exit(1)
}

val (rcScript, defaultRcFile) = format match {
case Bash.id | "bash" =>
val script = Bash.script(options.name)
val script = Bash.script(name)
val defaultRcFile = home / ".bashrc"
(script, defaultRcFile)
case Zsh.id | "zsh" =>
val completionScript = Zsh.script(options.name)
val completionScript = Zsh.script(name)
val zDotDir = Option(System.getenv("ZDOTDIR"))
.map(os.Path(_, os.pwd))
.getOrElse(home)
val defaultRcFile = zDotDir / ".zshrc"
val dir = completionsDir / "zsh"
val completionScriptDest = dir / "_scala"
val completionScriptDest = dir / s"_$name"
val content = completionScript.getBytes(Charset.defaultCharset())
if (!os.exists(completionScriptDest) || !Arrays.equals(os.read.bytes(completionScriptDest), content)) {
logger.log(s"Writing $completionScriptDest")
Expand All @@ -65,7 +77,7 @@ object InstallCompletions extends ScalaCommand[InstallCompletionsOptions] {
.map(os.Path(_, os.pwd))
.getOrElse(defaultRcFile)

val banner = options.banner.replace("{NAME}", options.name)
val banner = options.banner.replace("{NAME}", name)

val updated = ProfileFileUpdater.addToProfileFile(rcFile.toNIO, banner, rcScript, Charset.defaultCharset())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ final case class InstallCompletionsOptions(
@Recurse
directories: SharedDirectoriesOptions = SharedDirectoriesOptions(),

format: Option[String] = None,
@Name("shell")
format: Option[String] = None,

rcFile: Option[String] = None,
directory: Option[String] = None,
banner: String = "{NAME} CLI completions",
name: String = "scala"
banner: String = "{NAME} completions",
name: Option[String] = None
)
2 changes: 1 addition & 1 deletion project/settings.sc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ trait CliLaunchers extends SbtModule { self =>
def nativeImageOptions = Seq(
s"-H:IncludeResources=$localRepoResourcePath"
)
def nativeImageName = "scala"
def nativeImageName = "scala-cli"
def nativeImageClassPath = self.nativeImageClassPath()
def nativeImageMainClass = self.nativeImageMainClass()
}
Expand Down
16 changes: 14 additions & 2 deletions website/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Download the launcher from GitHub release assets with
```text
$ curl -fL https://github.com/VirtuslabRnD/scala-cli/releases/download/nightly/scala-cli-x86_64-apple-darwin.gz | gzip -d > scala-cli
$ chmod +x scala-cli
$ sudo mv scala-cli /usr/local/bin/scala-cli
$ mv scala-cli /usr/local/bin/scala-cli
```

Check that it runs fine by running its `about` command:
Expand All @@ -39,6 +39,9 @@ $ scala-cli about

### Windows

Note that the Windows manual installation requires [Visual C++ redistributable](https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0)
to be installed. See below for how to install it.

Download the launcher from GitHub release assets with
```text
> curl -fLo scala-cli.zip https://github.com/VirtuslabRnD/scala-cli/releases/download/nightly/scala-cli-x86_64-pc-win32.zip
Expand All @@ -50,7 +53,16 @@ Check that it runs fine by running its `about` command:
> scala-cli about
```

Note that this doesn't put the `scala-cli` command in the `PATH`. For that, you can create a directory, move the
If you get an error about `MSVCR100.dll` being missing, you have to install
[Visual C++ redistributable](https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0). A valid version is distributed with the Scala CLI launchers.
You can download it [here](https://github.com/VirtuslabRnD/scala-cli/releases/download/nightly/vc_redist.x64.exe),
and install it by double-clicking on it. Once the Visual C++ redistributable runtime is installed,
check that the Scala CLI runs fine by running its `about` command:
```text
> scala-cli about
```

Note that the commands above don't put the `scala-cli` command in the `PATH`. For that, you can create a directory, move the
launcher there, and add the directory to the `PATH` with
```text
> md "%USERPROFILE%/scala-cli"
Expand Down
2 changes: 2 additions & 0 deletions website/docs/reference/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ Available in commands:

#### `--format`

Aliases: `--shell`

#### `--rc-file`

#### `--directory`
Expand Down