#!/usr/bin/env hshell// Read a file and print it as Markdown to the console.echomd(read("README.md"))echo()echomd("## Notices and word wrapping")echo(Info("Some information. More text."))echo(Warning("A warning. More text."))echo(Error("An error. More text."))echo()echo("Roses are ${red("red")}, violets are ${blue("blue")}")
Run hshell demo.shell.kts or chmod +x demo.shell.kts; ./demo.shell.kts.
Use check for internal assertions and verify for things that are potentially user errors:
12345678
@Option(names=["--foo-path"])varfoo:Path? =null// If --foo-path is specified, verify it's a .txt file and then assert (crash) if it's empty.valtextLines:List<String>?=foo?.let{foo->verify(foo.name.endsWith(".txt"),"If --foo-path is specified it must be a .txt file")readLines(foo).also{check(it.isNotEmpty()){"File $foo should not be empty"}}}
ssh gives a subshell pointed at the remote host. Path objects keep track of what machine they were collected on:
1234567
vallocalFile=scriptDirPath/"data-file.txt"ssh("mike@hq.hydraulic.software"){// From local to remote.cp(localFile,"file-on-remote-host.txt")// And back.cp("file-on-remote-host.txt",localFile)}
You can omit the username and execute commands remotely: