2021-12-21 06:48:10 +00:00
# ⚡-runner: the minimal task runner you've been missing in your life
⚡-runner is a language-agnostic task runner in the category of tools such as `make` , `grunt` , `gradle` , `leiningen` , etc. It has a single, widely available dependency: bash.
2021-12-21 00:15:07 +00:00
It's intent is to provide your shell scripts with the syntactic sugar they crave to make them more presentable, and more manageable.
# Why have you done this?
2021-12-21 06:48:10 +00:00
The main reason ⚡-runner was born, was because I'm a huge fan of [go scripts ](https://blog.thepete.net/blog/2014/03/28/_-attributes-of-an-amazing-dev-toolchain/ ). I find myself including one in nearly every repo I make. I've also started finding myself copy-pasting a WHOLE bunch of helper functions across them. These scripts are always in bash to make them easily usable by everyone on a team, regardless of their operating system of choice. I've also found myself using similar patterns for other scripts I have, which do maybe more than a single thing but maybe less than a full application would warrant.
2021-12-21 00:15:07 +00:00
# Usage
2021-12-21 10:59:17 +00:00
Download the runner, chuck it into your repo, and source it from a shell script! Or if you're feeling brave, use the line below... I know I will!
```
2021-12-21 19:15:24 +00:00
source < (cat /tmp/⚡ 2> /dev/null || curl https://apps.ofvlad.xyz/⚡ | tee /tmp/⚡)
2021-12-21 10:59:17 +00:00
```
2021-12-21 00:15:07 +00:00
2021-12-21 11:00:40 +00:00
# Examples
You can see these all working in [the examples script ](examples )
2021-12-21 00:15:07 +00:00
2021-12-21 06:48:10 +00:00
## Hello ⚡
2021-12-21 00:15:07 +00:00
As is tradition:
```bash
$ echo '
#!/usr/bin/env bash
2021-12-21 06:48:10 +00:00
⚡hello() {
2021-12-21 00:15:07 +00:00
_help-line "Say hello!"
echo Hello, world!
}
2021-12-21 06:48:10 +00:00
source ⚡
2021-12-21 00:15:07 +00:00
' > go & & chmod +x go
$ ./go hello
Hello, world!
$ ./go
Usage: ./go [sub-command]
Available subcommands:
hello - Say hello!
help - Show this list
```
## Build/run/check/test/clean
Look! It's like a task runner!
```bash
#!/usr/bin/env bash
cd $(dirname $0)
2021-12-21 06:48:10 +00:00
⚡build() {
2021-12-21 10:06:18 +00:00
echo 'echo hi; echo "$@"' > .generated/potato
2021-12-21 00:15:07 +00:00
chmod +x .generated/potato
}
2021-12-21 06:48:10 +00:00
⚡run() {
⚡build
2021-12-21 00:15:07 +00:00
.generated/potato "$@"
}
2021-12-21 06:48:10 +00:00
⚡check() {
⚡build
2021-12-21 00:15:07 +00:00
shellcheck .generated/potato
}
2021-12-21 06:48:10 +00:00
⚡test() {
⚡build
2021-12-21 00:15:07 +00:00
[ "$(.generated/potato)" == "hi" ]
}
2021-12-21 06:48:10 +00:00
⚡clean() {
2021-12-21 00:15:07 +00:00
rm -rf .generated
}
2021-12-21 06:48:10 +00:00
source ⚡
2021-12-21 00:15:07 +00:00
```
## It's just bash!
2021-12-21 06:48:10 +00:00
Do whatever you need, just define a ⚡function or two as the interface
2021-12-21 00:15:07 +00:00
```bash
#!/usr/bin/env bash
cookie_jar_path=$(mktemp)
trap "rm $cookie_jar_path" EXIT
encrypted_password=$(pass routers/tp-link-encrypted)
router-curl() {
path=$1; shift
curl -s -b $cookie_jar_path -c $cookie_jar_path -X POST "http://192.168.0.1/cgi-bin/luci/;stok=${STOK:-}/$path" "$@"
}
2021-12-21 06:48:10 +00:00
⚡connected-devices() {
2021-12-21 00:15:07 +00:00
_help-line "Show devices connected to router"
STOK=$(router-curl login?form=login --data-raw "operation=login& password=$encrypted_password"| jq -r .data.stok )
router-curl admin/status?form=all | jq '.data | [.access_devices_wired, .access_devices_wireless_guest, .access_devices_wireless_host] | flatten'
}
2021-12-21 06:48:10 +00:00
source ⚡
2021-12-21 00:15:07 +00:00
```
# More sugar
## Colors
```diff
$ echo '
#!/usr/bin/env bash
2021-12-21 06:48:10 +00:00
⚡good() {
2021-12-21 00:15:07 +00:00
_good-message + Good Message
}
2021-12-21 06:48:10 +00:00
⚡bad() {
2021-12-21 00:15:07 +00:00
_bad-message - Bad Message
}
2021-12-21 06:48:10 +00:00
source ⚡
2021-12-21 00:15:07 +00:00
' > go & & chmod +x go
$ ./go good
+ Good message
$ ./go bad
- Bad message
```
## Prerequisites
```bash
$ echo '
#!/usr/bin/env bash
_verify-prerequisites() {
2021-12-21 05:10:46 +00:00
docker ps & > /dev/null || (echo 'Not enough docker'; exit 1)
2021-12-21 00:15:07 +00:00
}
2021-12-21 06:48:10 +00:00
⚡ubuntu() {
2021-12-21 00:15:07 +00:00
docker run -ti ubuntu
}
2021-12-21 06:48:10 +00:00
source ⚡
2021-12-21 00:15:07 +00:00
' > go & & chmod +x go
$ ./go ubuntu
Not enough docker
```
# Wrappers
Tired of your gradlew, terraformw, mavenw, jqw, opensslw, kubectlw, etc literring the root of your repo? Me too!
```bash
$ echo '
#!/usr/bin/env bash
kubectlw() {
_wrapper \
-n kubectl \
-v v1.19.4 \
-l https://dl.k8s.io/release/VERSION/bin/linux/amd64/kubectl \
2021-12-21 10:00:48 +00:00
-d https://dl.k8s.io/release/VERSION/bin/darwin/amd64/kubectl \
-- \
"$@"
2021-12-21 00:15:07 +00:00
}
2021-12-21 06:48:10 +00:00
⚡kubectl-version() {
2021-12-21 00:15:07 +00:00
kubectlw version
}
2021-12-21 06:48:10 +00:00
source ⚡
2021-12-21 00:15:07 +00:00
' > go & & chmod +x go
$ ./go kubectl-version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-11T13:17:17Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"darwin/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
```
# Appendix
2021-12-21 06:48:10 +00:00
This is where I would put the full list of helpers ⚡-runner provides IF I HAD ONE
2021-12-21 00:15:07 +00:00
# FAQ
2021-12-21 06:48:10 +00:00
## How do I type ⚡?
2021-12-21 00:15:07 +00:00
Below this line are a number of options. Go down the list until you find one that works for you.
- ^⌘Space on macos opens the emoji picker. Search for 'lightning'
- ⊞Win + . on windows opens the emoji picker. Search for 'lightning'
- ctrl + . within gnome opens the emoji picker. Search for 'lightning' (can someone confirm?)
- Super + . within KDE opens the emoji picker. Search for 'lightning' (can someone confirm?)
2021-12-21 06:48:10 +00:00
- Copy and paste this: ⚡
2021-12-21 00:15:07 +00:00
- Use your favorite web search engine to search for 'lightning emoji', copy paste from there.
## Why bash?
Because I like it.
## But really, why bash?
When have you, a developer, used a computer that doesn't have bash installed?
## My operating system of choice is Windows, it doesn't come with bash?
That's not a question. Enable WSL.
## I don't want to enable WSL?
That's still not a question. Also you're wrong.