Skip to content

Instantly share code, notes, and snippets.

@lhns
Last active December 1, 2022 14:24
Show Gist options
  • Save lhns/ee821a5cd1b2031856b21a0e78e1ecc9 to your computer and use it in GitHub Desktop.
Save lhns/ee821a5cd1b2031856b21a0e78e1ecc9 to your computer and use it in GitHub Desktop.
Cross platform scripts (scala script)
def universalScript(shellCommands: String,
cmdCommands: String,
shebang: Boolean): String = {
Seq(
if (shebang) "#!/usr/bin/env sh" else "",
"@ 2>/dev/null # 2>nul & echo off & goto BOF\r",
":",
shellCommands.replaceAll("\r?\n", "\n"),
"exit",
Seq(
"",
":BOF",
cmdCommands.replaceAll("\r?\n", "\r\n"),
"exit /B %errorlevel%",
""
).mkString("\r\n")
).filterNot(_.isEmpty).mkString("\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment