hshell¶
A bash competitor that lets you write shell-like scripts in Kotlin, with many other useful features that bash doesn't provide.
Warning
This site provides docs for an unreleased product! PROCEED WITH CAUTION AND LOW EXPECTATIONS.
Let's get started¶
demo.shell.kts | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Run hshell demo.shell.kts
or chmod +x demo.shell.kts; ./demo.shell.kts
.
List directories and print tables¶
Print the current directory contents as colored ls
style output, and a table:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Find the path to the script, and its containing directory:
1 2 |
|
Assertions¶
If a path assertion fails the user is shown the contents of the nearest directory and a spelling error suggestion.
1 2 |
|
Use check
for internal assertions and verify
for things that are potentially user errors:
1 2 3 4 5 6 7 8 |
|
Other string utilities¶
1 |
|
File ops¶
See shell API.
Dependencies¶
Brace expansion in coordinates works:
1 2 3 4 5 6 |
|
XML¶
1 2 3 4 5 6 7 8 9 10 |
|
Cleaning up¶
Instead of writing foo.use { foo -> foo.whatever() }
to clean things up, you can write foo.closeAtEnd().whatever()
:
1 |
|
The closeAtEnd()
function uses defer
to register a code block to run when the script finishes:
1 2 |
|
The last block deferred is run first.
Use exit(exitCode)
to terminate early. Don't call exitProcess
unless you're sure you want immediate termination without any finally
or deferred blocks running.
Disk caching¶
A LocalDiskCache
will give you a directory associated with an arbitrary string key, passing it to a handler to fill with content if
the key misses in the cache:
1 2 3 4 5 |
|
The cache will automatically keep its size in check, is thread safe and can be configured in various ways. You can also force cache misses and edit content in place.