- Introduce `clone-taskfile` function to manage taskfile repository cloning and pulling - Modify `dev-11ty` command to automatically open the browser at `http://localhost:8080/` - Reorder static variable declarations for better script organization - Improve output formatting with colored Git status messages
167 lines
5.3 KiB
Markdown
167 lines
5.3 KiB
Markdown
---
|
|
layout: layouts/base.njk
|
|
permalink: /
|
|
---
|
|
|
|
<hgroup>
|
|
<h1>./task</h1>
|
|
<p>Run any project.</p>
|
|
</hgroup>
|
|
|
|
[](https://codeberg.org/janikvonrotz/taskfile.build/actions?workflow=build.yml) 
|
|
|
|
---
|
|
|
|
The task file is a simple bash script and standardized interface for all software projects.
|
|
|
|
It is to be understood as a software development pattern to standardize the installation, configuration and execution of different software frameworks.
|
|
|
|
## Specification
|
|
|
|
The specification is a short guide to set up a task file for a Python project.
|
|
|
|
Create a file `task` in your project.
|
|
|
|
```bash
|
|
touch task
|
|
```
|
|
|
|
Ensure it is executable.
|
|
|
|
```bash
|
|
chmod +x task
|
|
```
|
|
|
|
First add the bash shebang.
|
|
|
|
```bash
|
|
#!/usr/bin/env bash
|
|
```
|
|
|
|
Then append the abort on error setting.
|
|
|
|
```bash
|
|
set -e
|
|
```
|
|
|
|
Load environment variables from the `.env` file.
|
|
|
|
```bash
|
|
if [[ -a ".env" ]]; then
|
|
source .env
|
|
fi
|
|
```
|
|
|
|
Add a help function.
|
|
|
|
```bash
|
|
help-table() {
|
|
local cmd_width=10
|
|
local opt_width=6
|
|
local desc_width=40
|
|
local column="| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n"
|
|
|
|
printf "$column" 'Command' 'Option' 'Description'
|
|
echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((desc_width + 2)) '' | tr ' ' '-')|"
|
|
printf "$column" 'help' '[grep]' 'Show help for commands.'
|
|
printf "$column" 'install' '' 'Setup the local environment.'
|
|
printf "$column" 'lint' '' 'Run pre-commit and update index.html.'
|
|
printf "$column" 'version' '' 'Show version of required tools.'
|
|
}
|
|
|
|
help() {
|
|
echo
|
|
if [[ -n "$1" ]]; then
|
|
help-table | grep -i "$1" | column -t -s'|'
|
|
else
|
|
echo 'task <command> [options]'
|
|
echo
|
|
echo 'commands:'
|
|
echo
|
|
help-table
|
|
fi
|
|
echo
|
|
}
|
|
```
|
|
|
|
Setup the command functions.
|
|
|
|
```bash
|
|
install() {
|
|
echo 'Setup venv and install python dependencies'
|
|
uv venv env
|
|
source env/bin/activate
|
|
uv pip install pre-commit
|
|
}
|
|
|
|
lint() {
|
|
source env/bin/activate
|
|
|
|
echo 'Run pre-commit'
|
|
pre-commit run --all-file
|
|
}
|
|
|
|
version() {
|
|
uv --version
|
|
}
|
|
```
|
|
|
|
Finish the task file with command switch cases.
|
|
|
|
```bash
|
|
if [[ "$1" == *","* ]]; then
|
|
# Split comma-separated commands
|
|
IFS=',' read -ra COMMANDS <<< "$1"
|
|
for cmd in "${COMMANDS[@]}"; do
|
|
# Trim whitespace
|
|
cmd=$(echo "$cmd" | xargs)
|
|
if declare -f "$cmd" > /dev/null; then
|
|
"$cmd"
|
|
else
|
|
echo "Unknown command: $cmd"
|
|
help
|
|
exit 1
|
|
fi
|
|
done
|
|
elif declare -f "$1" > /dev/null; then
|
|
"$1" "${@:2}"
|
|
else
|
|
case "$1" in
|
|
all)
|
|
install
|
|
lint
|
|
;;
|
|
*)
|
|
echo "Unknown command: $1"
|
|
help
|
|
exit 1
|
|
;;
|
|
esac
|
|
fi
|
|
```
|
|
|
|
These are the main parts of every task file script.
|
|
|
|
Now see [usage](/usage) on how to use the task file.
|
|
|
|
## Naming
|
|
|
|
The naming of functions is important. There are basically two styles:
|
|
|
|
1. Action + Object
|
|
2. Object + Action
|
|
|
|
The task file functions use the first style. The name of the function starts with an action followed by an object. The object name can be singular or plural.
|
|
|
|
**Examples for actions**: <span id="actions">activate, install, dev, develop, init, build, start, update, remove, delete, enable, disable, template, convert, create, edit, change, get, set, patch, fetch, generate, push, pull, import, export, list, publish, release, test, setup, prepare, restart, stop, store, restore, translate, upgrade, zip, visualize, sync, switch, run, reset, load, dump, checkout, commit, drop, deploy, handle, trigger, render, lint, uninstall, split, parse, fix, refactor, transform, cat, ls, rm, serve, help, show, filter, login, logout, encrypt, decrypt, upload, download, analyse, transpile, compile, minify, copy</span>
|
|
|
|
**Examples for objects**: <span id="objects">env, venv, submodule, container, database, snippet, model, module, repo, mail, doc, dependency, view, user, vault, file, host, node, log, password, hash, script, requirement, part, component, system, workspace, image, process, state, platform, dir, folder, readme, overview, lang, level, request, response, result, worker, server, proxy, workflow, volume, network, package, field, value, secret, chart, node, edge, function, method, firewall, html, css, image, svg, style, query, native, group, notebook</span>
|
|
|
|
**Objects can be tools**: <span id="object-tools">odoo, vupress, nodejs, zsh, bash, fish, podman, kind, minikube, helm, nvim, docker, podman, rust, python, tmux, vim, helix, system, git, pass, llm, sql, dotenv, javascript, vue, vite, astro, typescript, turbo, pnpm, eslint, jenkins, k8s, nextcloud, postgres, metabase, ansible, prometheus, grafana, hugo, deno, bun, babel, panda, gulp, grunt, electron, react, express, mongodb, angular, ionic, meteor, webpack, bower, jupyter</span>
|
|
|
|
<button id="generate-function-names">Generate Function Names</button> <ul id="function-names"> <!-- Random function names will be inserted here by JS --> </ul>
|
|
|
|
## Style
|
|
|
|
The bash scripts follow the [Bash Style Guide | ysap.sh](https://style.ysap.sh/). Have a look at the [AGENTS.md](/AGENTS) for details on the applied styling.
|