Skip to content

Commit

Permalink
Updated universal script and removed shebang line by default (#789)
Browse files Browse the repository at this point in the history
* changed the method used to skip the script for the other platform to be in sync with com-lihaoyi/mill#264

* set shebang parameter to be false by default

* updated docs on how to prepend the shebang line on linux and added info on how to download on windows
  • Loading branch information
LolHens authored and robby-phd committed Mar 31, 2018
1 parent f07633d commit 7446d8f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
39 changes: 22 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,33 @@ lazy val amm = project

assemblyOption in assembly := (assemblyOption in assembly).value.copy(
prependShellScript = {
def universalScript(shellCommands: Seq[String],
cmdCommands: Seq[String],
shebang: Boolean = true): Seq[String] = {
def universalScript(shellCommands: String,
cmdCommands: String,
shebang: Boolean = false): String = {
Seq(
Seq("#!/usr/bin/env sh")
.filter(_ => shebang),
Seq("shopt -s expand_aliases", "alias ::=''")
.map(line => s":; $line"),
(shellCommands :+ "exit")
.map(line => s":: $line"),
"@echo off" +: cmdCommands :+ "exit /B",
Seq("\r\n")
).flatten
if (shebang) "#!/usr/bin/env sh" else "",
"@ 2>/dev/null # 2>nul & echo off & goto BOF\r",
":",
shellCommands.replaceAll("\r\n|\n", "\n"),
"exit",
Seq(
"",
":BOF",
"@echo off",
cmdCommands.replaceAll("\r\n|\n", "\r\n"),
"exit /B %errorlevel%",
""
).mkString("\r\n")
).filterNot(_.isEmpty).mkString("\n")
}

def defaultUniversalScript(javaOpts: Seq[String] = Seq.empty, shebang: Boolean = true): Seq[String] = {
def defaultUniversalScript(javaOpts: Seq[String] = Seq.empty, shebang: Boolean = false): Seq[String] = {
val javaOptsString = javaOpts.map(_ + " ").mkString
universalScript(
shellCommands = Seq(s"exec java -jar $javaOptsString" + """$JAVA_OPTS "$0" "$@""""),
cmdCommands = Seq(s"java -jar $javaOptsString" + """%JAVA_OPTS% "%~dpnx0" %*"""),
Seq(universalScript(
shellCommands = s"""exec java -jar $javaOptsString$$JAVA_OPTS "$$0" "$$@"""",
cmdCommands = s"""java -jar $javaOptsString%JAVA_OPTS% "%~dpnx0" %*""",
shebang = shebang
)
))
}

// G1 Garbage Collector is awesome https://github.com/lihaoyi/Ammonite/issues/216
Expand Down
6 changes: 6 additions & 0 deletions readme/Footer.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,12 @@
@hl.sh
@readme.Sample.unstableCurl

@p
The latest build can also be run on windows. Just save it as amm.bat:

@p
@lnk(ammonite.Constants.unstableCurlUrl)

@p
Or usage in an SBT project

Expand Down
6 changes: 5 additions & 1 deletion readme/Sample.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ object Sample{
s"$$ sudo curl -L -o /usr/local/bin/amm " +
curlUrl +
" && sudo chmod +x /usr/local/bin/amm && amm"
def unstableCurlCommand(curlUrl: String) =
s"""$$ sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L """ +
curlUrl +
") > /usr/local/bin/amm && chmod +x /usr/local/bin/amm' && amm"
val replCurl = curlCommand(ammonite.Constants.curlUrl)
val unstableCurl = curlCommand(ammonite.Constants.unstableCurlUrl)
val unstableCurl = unstableCurlCommand(ammonite.Constants.unstableCurlUrl)
val filesystemCurl =
"$ mkdir -p ~/.ammonite && curl -L -o ~/.ammonite/predef.sc https://git.io/vHaKQ"
val cacheVersion = 6
Expand Down

0 comments on commit 7446d8f

Please sign in to comment.