- No installation
- No dependencies
- No overhead
Replace your convoluted build system with vanilla bash.
#!/bin/bash
set -euo pipefail # Error handling: -e stops on errors. -u stops on unset variables. -o pipefail stops pipelines on fail: https://mobile.twitter.com/b0rk/status/1314345978963648524
build() {
echo "I am ${FUNCNAME[0]}ing" # βΆοΈ doit build ποΈ I am building
}
deploy() {
echo "I am ${FUNCNAME[0]}ing with args $1 $2 $3" # βΆοΈ doit deploy a b c ποΈ I am deploying with args a b c
}
clean() { echo "I am ${FUNCNAME[0]}ing in just one line." ;}
required() {
which docker || { echo "Error: Docker is not installed"; exit 1 ;}
}
all() {
required && clean && build && deploy a b c # Continues chain on success.
}
[ "$#" -gt 0 ] || echo "Usage: doit task [options]" && "$@" # π’ DO IT!
Save as doit.sh
use chmod +x ./doit.sh
Do task: ./doit.sh build
echo "alias doit='./doit.sh'" >> ~/.bashrc
- Open new shell.
- You can now use
doit
[ "$#" -gt 0 ] && { "$@"; } || echo -e "Usage: $0 task [options]\nTasks:"; printf "\t%s\n" $(compgen -A function) # π’ DO IT!
help() { # Show help message.
echo -e "Usage: $0 task [options]\nTasks:"
for func in $(compgen -A function | grep -E '^_' -v); do printf "\t$func \t \e[92m $(grep "^$func()" $0 | grep -oP '(?<=# ).*')" ; printf " \e[0m \n"; done | column -t -s $'\t'
}
[ "$#" -gt 0 ] && { "$@"; } || help; # π’ DO IT!
. $(dirname $0)/helpers.sh
Run script from URL, including public or private github repositories!
required() {
which docker || { echo "Error: Docker is not installed"; exit 1 ;}
$0 docker/install_check # Easily run an online script.
}
online() {
echo "π Find online? (y/n)"; read CHOICE && [[ $CHOICE = [yY] ]] || (echo "Cancelled"; exit 1)
{ curl -fsSL https://raw.githubusercontent.com/gnat/doit/main/extra/$1.sh | bash --login -s -- ${@:2}; } && exit 1 || echo "Not found: '$1'"
}
[ "$#" -gt 0 ] || echo -e "Usage: $0 command [options]" && { "$@" || online "$@"; } # π’ DO IT!
# Run online script.
curl -fsSL https://raw.githubusercontent.com/gnat/doit/main/extra/helpers.sh | bash
# Import online script.
. <(curl -fsSL https://raw.githubusercontent.com/gnat/doit/main/extra/helpers.sh)
online() {
URL="https://YOUR_PRIVATE_GITHUB/main/$1.sh"
echo "π Find online? (y/n) ($URL) "; read CHOICE && [[ $CHOICE = [yY] ]] || (echo "Cancelled"; exit 1)
{ curl -fsSL "$URL -H 'Authorization: Token YOUR_PRIVATE_ACCESS_CODE'" | bash --login -s -- ${@:2}; } ||
echo "Not found: '$1'"
}
online() {
URLS=(
"https://YOUR_PRIVATE_GITHUB/main/$1.sh -H 'Authorization: Token YOUR_PRIVATE_ACCESS_CODE'"
"https://raw.githubusercontent.com/gnat/doit/main/extra/$1.sh"
"https://raw.githubusercontent.com/gnat/doit_again/main/extra/$1.sh"
)
for URL in "${URLS[@]}"; do
echo "π Find online? (y/n) (${URL%% *}) "; read CHOICE && [[ $CHOICE = [yY] ]] || { echo "Skipping"; continue; }
{ curl -fsSL "$URL" | bash --login -s -- ${@:2}; } && exit # Success
done
echo "Not found: '$1'"
}
- Bash Manual
- Bash Source Code
- Bash Cheat Sheet
- Bash Variable Parameter Expansions
- Shell Explainer
- Why "pipefail"?
- CURL guide
curl https://URL/script.sh | bash
breaks some user input prompts such asread
. For workarounds, see examples/choices. If you do not want to use a different convention for calling online scripts, you may consider passing script arguments only.
- This simulates a user session, and is required to install certain apps such as Rootless Docker.