Last active
July 22, 2023 16:32
-
-
Save Nebucatnetzer/b7dc6863817fda02d4bed2591e5d3049 to your computer and use it in GitHub Desktop.
A BASH script which acts as a simple task runner like Just or abused Makefiles.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script allows you to run tasks with `dev.sh TASKNAME`. | |
# Create a function and assign the function to a desired argument. | |
# For example the function `run` can be executed with: | |
# `dev.sh run` or `dev.sh start` | |
# If no argument is provided it will show the available options and their | |
# description. | |
declare -A tasks | |
declare -A descriptions | |
run () { | |
echo "I'm a command." | |
} | |
descriptions["run"]="Run the project." | |
tasks["run"]=run | |
descriptions["start"]="Alias for run." | |
tasks["start"]=run | |
setup () { | |
echo "Another command." | |
} | |
tasks["setup"]=setup | |
descriptions["setup"]="Setup the project." | |
# Main logic to select the function matching the argument. { | |
# only one task at a time | |
if [ $# != 1 ]; then | |
printf "usage: dev <task_name>\n\n" | |
for task in "${!tasks[@]}" | |
do | |
echo "$task - ${descriptions[$task]}" | |
done | |
else | |
# Check if task is available | |
if [[ -v "tasks[$1]" ]] ; then | |
${tasks["$1"]} | |
else | |
echo "Task not found." | |
fi | |
fi | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment