A CLI frontend for your bash scripts.
Parses scripts and pretty prints the functions it finds. Similar to run_lib but rustier, and to runsh but better.
Say you have a script called script.sh
that looks like this:
```
some_function() { echo "hello world from a script" echo "foobar" sleep 1 echo "ending function now" }
yetmorefunctions() { echo "hello from another function" } ```
You can access it by executing lk
, and it'll find the script and should you what functions are available. Then you can run something like this to execute the function:
bash
lk script.sh some_function
This is a tool that I use a lot, and "lk" is short and ergonomic. As long as you're reasting on the home keys.
From the crate:
bash
cargo install lk
bash
cargo install --force lk
Just execute lk
and follow the instructions.
lk
will extract comments in the file header, if it finds any, and display them alongside all your runnable functions. It relies on these comments following the form in the Google Shell Style Guide, i.e. like this:
```bash
#
```
I already wrote this in bash and called it run_lib. There are a few reasons why this might be better. Here are some considerations:
1. A Rust executable is easier to distribute via cargo
. It's easier for people to update their version.
2. Integration with a script is more or less the same.
3. The processing is much easier in Rust than it is in bash, i.e. finding and displaying multi-line comments.
4. Rust so hot right now.
We don't want binaries because we won't be reading any functions from them.
For testing I took the smallest binary from my /usr/bin
and copied it into ./tests/
_
prefix.runsh
, where it used non-0 exit codes to run the scripts.