diff --git a/AGENTS.md b/AGENTS.md index 6c5dec4..a721f65 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,20 @@ # Agents.md -## Bash +## General agent guidance + +This section outlines the universal rules and expectations for any LLM agent working within this repository. + +**Safety and Quality First:** The highest priority is to produce secure, well-documented, and high-quality code. Do not introduce vulnerabilities, hardcoded secrets, or unreadable code. + +**Propose a Plan:** For any new task, first provide a brief plan of action. This plan should clearly outline the intended changes and the rationale behind them. + +**Maintain Context:** Before making any changes, an agent must read and understand the relevant files, including the project's main documentation and existing code structure. + +**Clear Contributions:** All contributions must be submitted via a pull request with a clear, concise commit message and a brief description of the changes. + +## Coding conventions + +### Bash The following guideline is heavily based on the [Bash Style Guide | ysap.sh](https://style.ysap.sh/), which should be considered the primary reference for style. Adhere to the following principles to ensure scripts are safe, predictable, and maintainable. @@ -13,11 +27,11 @@ The following guideline is heavily based on the [Bash Style Guide | ysap.sh](htt **Always quote variable expansions** (`"$var"`) to prevent word-splitting and globbing issues. -**Variables:** Theck if the var is used locally or from environment. +**Variables:** Distinct between local and environment vars. -- Use lowercase variable names (e.g., `my_var`). +- Use lowercase names for local variables (e.g., `buildx_output`). - Use `local` for all variables inside functions. -- Use uppercase names for environment variables (e.g. `TASK_CONFIG_DIR`) +- Use uppercase names for environment variables (e.g. `BUILDX_PLATFORM`) **Functions:** diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d8b6553 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,48 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). + +## [Unreleased] + +### Added + +- New CHANGELOG.md file to document project changes following Keep a Changelog specifications + +### Changed + +- Updated `task` script to follow AGENTS.md bash guidelines: + - Changed shebang from `#!/bin/bash` to `#!/usr/bin/env bash` for portability + - Removed `function` keyword from all function definitions, using `func-name() {` syntax + - Updated all conditional tests from `[ ]` to `[[ ]]` for better functionality + - Converted local variables in `help-table()` function to lowercase with `local` keyword: + - `CMD_WIDTH` → `local cmd_width` + - `OPT_WIDTH` → `local opt_width` + - `DESC_WIDTH` → `local desc_width` + - `COLUMN` → `local column` + - Updated printf statements to use new lowercase variable names +- Updated `image/entrypoint.sh` script to follow AGENTS.md bash guidelines: + - Changed shebang from `#!/bin/bash` to `#!/usr/bin/env bash` for portability + - Updated all conditional tests from `[ ]` to `[[ ]]`: + - `if [[ -z "$GIT_URL" ]]` + - `if [[ ! -d "$GIT_PATH" ]]` + - `if [[ -f "$GIT_PATH/.gitmodules" ]]` + - `if [[ -f "${GIT_PATH}/task" ]]` + - `if [[ -z "$TASK_COMMANDS" ]]` +- Updated bash code snippets in README.md to follow AGENTS.md bash guidelines: + - Updated shebangs to use `#!/usr/bin/env bash` + - Removed `function` keyword from all function definitions + - Updated conditional tests from `[ ]` to `[[ ]]` + - Updated arithmetic comparisons to use `(( ))` syntax where appropriate + - Updated local variables within functions to use lowercase names with `local` keyword: + - `DATABASE` → `local database` in `drop-db()` function + - `FOLDER` → `local folder` in `render()` function + - Variables in `convert-vault-file()` function: + - Variables in `process-data()` function: + - Updated `deploy()` function to use `[[ -z "$1" ]]` instead of `test -z "$1"` +- Further updated bash code snippets in README.md to ensure full compliance with AGENTS.md guidelines: + - Updated remaining `[ -n "$1" ]` conditions to use `[[ -n "$1" ]]` syntax + - Updated remaining `test -z "$1"` conditions to use `[[ -z "$1" ]]` syntax + - Ensured all local variables follow lowercase naming convention + - Verified all conditional expressions use `[[ ]]` instead of `[ ]` or `test` \ No newline at end of file diff --git a/README.md b/README.md index a0c1d63..13f0b3c 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ chmod +x task - First add the bash shebang. ```bash -#!/bin/bash +#!/usr/bin/env bash ``` - Then append the abort on error setting. @@ -55,23 +55,22 @@ fi - Add a help function. ```bash -function help-table() { - CMD_WIDTH=10 - OPT_WIDTH=6 - DESC_WIDTH=40 - 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" "all" "" "Run all tasks." - 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-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." } -function help() { +help() { echo - if [ -n "$1" ]; then + if [[ -n "$1" ]]; then help-table | grep -i "$1" | column -t -s'|' else echo "task [options]" @@ -87,18 +86,18 @@ function help() { - Setup the command functions. ```bash -function version() { +version() { uv --version } -function install() { +install() { echo "Setup venv and install python dependencies" uv venv env source env/bin/activate uv pip install pre-commit } -function lint() { +lint() { source env/bin/activate echo "Run pre-commit" @@ -158,7 +157,7 @@ The task file functions use the first style. The name of the function starts wit ## Style -The bash scripts follow the [Bash Style Guide | ysap.sh](https://style.ysap.sh/). The style converstions are +The bash scripts follow the [Bash Style Guide | ysap.sh](https://style.ysap.sh/). Have a look at the [AGENTS.md](./AGENTS.md) for details on the applied styling. ## Patterns @@ -169,9 +168,9 @@ The task file showed above is very basic. Commands can have parameters and call Fallback to a default value for a parameter. ```bash -function build() { +build() { PLATFORM="amd64" - if [ -n "$1" ]; then + if [[ -n "$1" ]]; then PLATFORM="$1" fi ``` @@ -181,8 +180,8 @@ function build() { Check the first param and exit if it is empty. ```bash -function deploy() { - if test -z "$1"; then echo "\$1 is empty."; exit; fi +deploy() { + if [[ -z "$1" ]]; then echo "\$1 is empty."; exit; fi ``` ### Prompt for input @@ -190,10 +189,10 @@ function deploy() { Use `read` to ask for inputs. ```bash -if [ -z "$2" ]; then - read -p "Enter the task description: " TASK_DESCRIPTION +if [[ -z "$2" ]]; then + read -p "Enter the task description: " task_description else - TASK_DESCRIPTION="$2" + task_description="$2" fi ``` @@ -211,7 +210,7 @@ GIT_BRANCH=$(git symbolic-ref --short -q HEAD) Create a parameterized file from a template. Requires `envsubst`. ```bash -function template-with-env() { +template-with-env() { echo "Template $CONFIGURATION_FILE" export CONFIGURATION_1 @@ -226,8 +225,8 @@ function template-with-env() { Initialize Python virtual env with uv. ```bash -function init-venv() { - if [ ! -d "venv$GIT_BRANCH" ]; then +init-venv() { + if [[ ! -d "venv$GIT_BRANCH" ]]; then echo "Init venv$GIT_BRANCH with $(uv --version)." uv venv "venv$GIT_BRANCH" fi @@ -237,7 +236,7 @@ function init-venv() { ### Activate Python virtual env ```bash -function activate-venv() { +activate-venv() { echo "Source virtualenv venv$GIT_BRANCH." source "venv$GIT_BRANCH/bin/activate" echo "$(python --version) is active." @@ -249,9 +248,9 @@ function activate-venv() { Run a Python script. ```bash -function generate-password-hash() { +generate-password-hash() { activate-venv - if test -z "$1"; then echo "\$1 is empty."; exit; fi + if [[ -z "$1" ]]; then echo "\$1 is empty."; exit; fi PASSWORD_PLAIN="$1" bin/password-hash } @@ -275,8 +274,7 @@ print(crypt_context.hash(password)) Assuming you have a `docker-compose.yml` and would like to start selected or all containers. ```bash -function start() { - +start() { if [[ "$1" =~ "db" ]]; then docker compose up -d db fi @@ -305,14 +303,14 @@ Start all containers with `task start` and selected with `task start db,admin`. Use `docker exec -i` to run commands in a container. ```bash -function drop-db() { - DATABASE="$1" - if [ -z "$DATABASE" ]; then - DATABASE="example" +drop-db() { + local database="$1" + if [[ -z "$database" ]]; then + database="example" fi - docker exec -i db psql "postgres://odoo:odoo@localhost:5432/postgres" -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$DATABASE';" - docker exec -i db psql "postgres://odoo:odoo@localhost:5432/postgres" -c "DROP DATABASE \"$DATABASE\";" + docker exec -i db psql "postgres://odoo:odoo@localhost:5432/postgres" -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '$database';" + docker exec -i db psql "postgres://odoo:odoo@localhost:5432/postgres" -c "DROP DATABASE \"$database\";" } ``` @@ -321,11 +319,11 @@ function drop-db() { Use `for` to loop over file, folders or arrays. ```bash -function render() { +render() { echo "Update index.html for all folders" - for FOLDER in ./*; do - if [ -f "$FOLDER/README.md" ]; then - cd "$FOLDER" || exit + for folder in ./*; do + if [[ -f "$folder/README.md" ]]; then + cd "$folder" || exit md2html README.md _site/index.html cd .. || exit fi @@ -338,50 +336,50 @@ function render() { With this function you can split a file into multiple parts whenever a specific keyword is matching. In this example the keyword is `!vault`. ```bash -function convert-vault-file() { - FILE_PATH="$1" - TEMP_FILE=$(mktemp) - TEMP_PART_FILE=$(mktemp) - WRITE_FINISHED=false - CURRENT_KEY="" +convert-vault-file() { + local file_path="$1" + local temp_file=$(mktemp) + local temp_part_file=$(mktemp) + local write_finished=false + local current_key="" - while IFS= read -r LINE; do + while IFS= read -r line; do # Check for keyword - if [[ "$LINE" =~ "!vault" ]]; then + if [[ "$line" =~ "!vault" ]]; then # Process previous vault entry if it exists - if [ "$WRITE_FINISHED" = true ] && [ -n "$CURRENT_KEY" ] && [ -s "$TEMP_PART_FILE" ]; then + if [[ "$write_finished" = true ]] && [[ -n "$current_key" ]] && [[ -s "$temp_part_file" ]]; then # Decrypt part file and write to assemble file - ansible-vault decrypt "$TEMP_PART_FILE" - VALUE=$(cat "$TEMP_PART_FILE") - echo "$CURRENT_KEY: $VALUE" >> "$TEMP_FILE" + ansible-vault decrypt "$temp_part_file" + local value=$(cat "$temp_part_file") + echo "$current_key: $value" >> "$temp_file" fi # Set up for new vault entry - CURRENT_KEY=$(echo "$LINE" | cut -d':' -f1) + current_key=$(echo "$line" | cut -d':' -f1) # Clear the file - : > "$TEMP_PART_FILE" + : > "$temp_part_file" # Flag as ready to write - WRITE_FINISHED=true + write_finished=true else - if [ "$WRITE_FINISHED" = true ]; then + if [[ "$write_finished" = true ]]; then # Pipe into part file - echo "$LINE" >> "$TEMP_PART_FILE" + echo "$line" >> "$temp_part_file" fi - fi - done < "$FILE_PATH" + done + done < "$file_path" # Process the final vault entry - if [ "$WRITE_FINISHED" = true ] && [ -n "$CURRENT_KEY" ] && [ -s "$TEMP_PART_FILE" ]; then - ansible-vault decrypt "$TEMP_PART_FILE" - VALUE=$(cat "$TEMP_PART_FILE") - echo "$CURRENT_KEY: $VALUE" >> "$TEMP_FILE" + if [[ "$write_finished" = true ]] && [[ -n "$current_key" ]] && [[ -s "$temp_part_file" ]]; then + ansible-vault decrypt "$temp_part_file" + local value=$(cat "$temp_part_file") + echo "$current_key: $value" >> "$temp_file" fi # Output assembled file - cat "$TEMP_FILE" + cat "$temp_file" # Cleanup temp files - rm -f "$TEMP_FILE" - rm -f "$TEMP_PART_FILE" + rm -f "$temp_file" + rm -f "$temp_part_file" } ``` @@ -399,35 +397,35 @@ scripts The following function lists the scripts and asks for the number of scripts to run. Every script until the entered number is concatenated and executed. ```bash -function process-data() { +process-data() { while true; do - SCRIPTS=($(ls scripts)) + local scripts=($(ls scripts)) echo -e "Available scripts:\n" - for INDEX in "${!SCRIPTS[@]}"; do - echo "$((INDEX+1)): ${SCRIPTS[$INDEX]}" + for index in "${!scripts[@]}"; do + echo "$((index+1)): ${scripts[$index]}" done echo "" - read -p "Enter the number of scripts to run (or 'q' to quit): " USER_INPUT - if [ "${USER_INPUT}" = "q" ]; then + read -p "Enter the number of scripts to run (or 'q' to quit): " user_input + if [[ "$user_input" = "q" ]]; then break fi - TEMP_FILE=$(mktemp) - for INDEX in "${!SCRIPTS[@]}"; do - if [ $USER_INPUT -ge $((INDEX+1)) ]; then - cat "scripts/${SCRIPTS[$INDEX]}" >> "$TEMP_FILE" - echo >> "$TEMP_FILE" + local temp_file=$(mktemp) + for index in "${!scripts[@]}"; do + if (( $user_input >= $((index+1)) )); then + cat "scripts/${scripts[$index]}" >> "$temp_file" + echo >> "$temp_file" fi done clear echo -e "\nPython Output:\n\n---" - python "$TEMP_FILE" - EXIT_CODE=$? + python "$temp_file" + local exit_code=$? echo -e "---\n" - echo -e "Exit code: $EXIT_CODE\n" - rm "$TEMP_FILE" + echo -e "Exit code: $exit_code\n" + rm "$temp_file" done } ``` @@ -443,7 +441,7 @@ With the output of `task help` the task commands can be completed. Completion for bash: `/etc/bash_completion.d/task_completions` ```bash -#!/bin/bash +#!/usr/bin/env bash _task_completions() { local cur prev commands @@ -551,34 +549,34 @@ pipeline { This website is built with a `task` file. Here is the source: ```bash -#!/bin/bash +#!/usr/bin/env bash set -e -function help-table() { - CMD_WIDTH=40 - OPT_WIDTH=6 - DESC_WIDTH=42 - COLUMN="| %-${CMD_WIDTH}s | %-${OPT_WIDTH}s | %-${DESC_WIDTH}s |\n" +help-table() { + cmd_width=20 + local opt_width=6 + desc_width=42 + 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" "all" "" "Run all tasks." - printf "$COLUMN" "build-11ty" "" "Build the 11ty website." - printf "$COLUMN" "build-image" "" "Build Docker image." - printf "$COLUMN" "commit-with-llm" "" "Commit with llm generated commit message." - printf "$COLUMN" "dev-11ty" "" "Run 11ty server." - printf "$COLUMN" "help" "[grep]" "Show help for commands." - printf "$COLUMN" "install" "" "Install node packages." - printf "$COLUMN" "lint" "" "Lint code with prettier." - printf "$COLUMN" "run" "" "Run Docker image." - printf "$COLUMN" "run-tests" "" "Test with shellcheck." - printf "$COLUMN" "serve-11y" "" "Serve the 11ty output folder." - printf "$COLUMN" "version" "" "Show version of required tools." + 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" "all" "" "Run all tasks." + printf "$column" "build-11ty" "" "Build the 11ty website." + printf "$column" "build-image" "" "Build Docker image." + printf "$column" "commit-with-llm" "" "Commit with llm generated commit message." + printf "$column" "dev-11ty" "" "Run 11ty server." + printf "$column" "help" "[grep]" "Show help for commands." + printf "$column" "install" "" "Install node packages." + printf "$column" "lint" "" "Lint code with prettier." + printf "$column" "run" "" "Run Docker image." + printf "$column" "run-tests" "" "Test with shellcheck." + printf "$column" "serve-11tyy" "" "Serve the 11ty output folder." + printf "$column" "version" "" "Show version of required tools." } -function help() { +help() { echo - if [ -n "$1" ]; then + if [[ -n "$1" ]]; then help-table | grep -i "$1" | column -t -s'|' else echo "task [options]" @@ -599,9 +597,9 @@ DOCKERFILE="image/Dockerfile" # Import commands -if [ -d "$HOME/taskfile.build/bin" ]; then +if [[ -d "$HOME/taskfile.build/bin" ]]; then for file in "$HOME/taskfile.build/bin/"*; do - if [ -f "$file" ]; then + if [[ -f "$file" ]]; then source "$file" fi done @@ -609,7 +607,7 @@ fi # Project commands -function run() { +run() { echo "Open http://localhost:8080 in your browser" docker run -p 8080:80 \ -e GIT_URL="https://git.taskfile.build" \ @@ -618,32 +616,32 @@ function run() { janikvonrotz/taskfile.build:latest } -function install() { +install() { pnpm install } -function dev-11ty() { +dev-11ty() { pnpm dlx @11ty/eleventy --serve } -function lint() { +lint() { pnpm exec prettier . --write } -function run-tests() { +run-tests() { echo "Test with shellcheck." shellcheck task } -function build-11ty() { +build-11ty() { pnpm dlx @11ty/eleventy } -function serve-11ty() { +serve-11ty() { pnpx serve ./_site } -function version() { +version() { echo "eleventy: $(pnpm dlx @11ty/eleventy --version)" } @@ -686,8 +684,8 @@ The repository of this website provides a library of reusable functions. Clone the repository into your home folder and ensure it is updated regurarly. ```bash -function clone-taskfile(){ - if [ ! -d "$HOME/taskfile.build" ]; then +clone-taskfile(){ + if [[ ! -d "$HOME/taskfile.build" ]]; then echo -e "\033[38;5;214mGit\033[0m: Clone taskfile repo" git clone https://git.taskfile.build "$HOME/taskfile.build" else @@ -700,9 +698,9 @@ function clone-taskfile(){ In your task file you can import these functions from the taskfile library. ```bash -if [ -d "$HOME/taskfile.build/bin" ]; then +if [[ -d "$HOME/taskfile.build/bin" ]; then for file in "$HOME/taskfile.build/bin/"*; do - if [ -f "$file" ]; then + if [[ -f "$file" ]]; then source "$file" fi done @@ -716,21 +714,27 @@ For autocomplete add the command to the help table. #### init-config-dir ```bash - printf "$COLUMN" "init-config-dir" "" "Setup task file config dir." +printf "$column" "init-config-dir" "" "Setup task file config dir." ``` #### template-dotenv ```bash - printf "$COLUMN" "template-dotenv" "" "Generate .env from .env.template." +printf "$column" "template-dotenv" "" "Generate .env from .env.template." ``` ### Python +Set git env vars. + +```bash +GIT_BRANCH=$(git symbolic-ref --short -q HEAD) +``` + #### init-venv ```bash - printf "$COLUMN" "init-venv" "" "Initialize and activate Python virtual env." +printf "$column" "init-venv" "" "Initialize and activate Python virtual env." ``` ### Environment @@ -738,67 +742,67 @@ For autocomplete add the command to the help table. #### create-odoo-env ```bash - printf "$COLUMN" "create-odoo-env" "[env]" "Create env file for Odoo instance." +printf "$column" "create-odoo-env" "[env]" "Create env file for Odoo instance." ``` #### create-nextcloud-env ```bash - printf "$COLUMN" "create-nextcloud-env" "[env]" "Create env file for Nextcloud Instance." +printf "$column" "create-nextcloud-env" "[env]" "Create env file for Nextcloud Instance." ``` #### list-env ```bash - printf "$COLUMN" "list-env" "" "List env files." +printf "$column" "list-env" "" "List env files." ``` #### show-env ```bash - printf "$COLUMN" "show-env" "[env]" "Output content of the env file." +printf "$column" "show-env" "[env]" "Output content of the env file." ``` #### copy-env ```bash - printf "$COLUMN" "copy-env" "[env][env]" "Copy env file." +printf "$column" "copy-env" "[env][env]" "Copy env file." ``` #### edit-env ```bash - printf "$COLUMN" "edit-env" "[env]" "Open env file in default editor." +printf "$column" "edit-env" "[env]" "Open env file in default editor." ``` #### load-env ```bash - printf "$COLUMN" "load-env" "[env]" "Load and export env file." +printf "$column" "load-env" "[env]" "Load and export env file." ``` #### rename-env ```bash - printf "$COLUMN" "rename-env" "[env][env]" "Rename env file." +printf "$column" "rename-env" "[env][env]" "Rename env file." ``` #### remove-env ```bash - printf "$COLUMN" "remove-env" "[env]" "Remove environment config." +printf "$column" "remove-env" "[env]" "Remove environment config." ``` #### backup-env-files ```bash - printf "$COLUMN" "backup-env-files" "[path]" "Archive and copy env files to target location." +printf "$column" "backup-env-files" "[path]" "Archive and copy env files to target location." ``` #### restore-env-files ```bash - printf "$COLUMN" "restore-env-files" "[path]" "Extract and copy env files from backup file." +printf "$column" "restore-env-files" "[path]" "Extract and copy env files from backup file." ``` ### LLM @@ -806,13 +810,13 @@ For autocomplete add the command to the help table. #### commit-with-llm ```bash - printf "$COLUMN" "commit-with-llm" "" "Commit with llm generated commit message." +printf "$column" "commit-with-llm" "" "Commit with llm generated commit message." ``` #### update-with-llm ```bash - printf "$COLUMN" "update-with-llm" "[glob][prompt]" "Feed files matching glob to LLM and apply changes." +printf "$column" "update-with-llm" "[glob][prompt]" "Feed files matching glob to LLM and apply changes." ``` ### Git @@ -820,7 +824,7 @@ For autocomplete add the command to the help table. #### update-submodule ```bash - printf "$COLUMN" "update-submodule" "" "Update git submodules." +printf "$column" "update-submodule" "" "Update git submodules." ``` ### Pass @@ -834,13 +838,13 @@ PASS_ENTRY=$(echo "env/${PWD##*/}" | tr '[:upper:]' '[:lower:]') #### save-dotenv-to-pass ```bash - printf "$COLUMN" "save-dotenv-to-pass" "" "Store content of .env in pass entry." +printf "$column" "save-dotenv-to-pass" "" "Store content of .env in pass entry." ``` #### load-dotenv=from-pass ```bash - printf "$COLUMN" "load-dotenv=from-pass" "" "Restore content to .env from pass entry." +printf "$column" "load-dotenv=from-pass" "" "Restore content to .env from pass entry." ``` ### KeePass @@ -856,13 +860,13 @@ KEEPASS_ENTRY=$(echo "env/${PWD##*/}" | tr '[:upper:]' '[:lower:]') #### save-dotenv-to-keepass ```bash - printf "$COLUMN" "save-dotenv-to-keepass" "" "Store content of .env in KeePass entry." +printf "$column" "save-dotenv-to-keepass" "" "Store content of .env in KeePass entry." ``` #### load-dotenv-from-keepass ```bash - printf "$COLUMN" "load-dotenv-from-keepass" "" "Restore content to .env from KeePass entry." +printf "$column" "load-dotenv-from-keepass" "" "Restore content to .env from KeePass entry." ``` ### Docker @@ -880,11 +884,11 @@ DOCKER_CONFIG="$HOME/.docker/$CONTAINER_REGISTRY/" #### login-docker ```bash - printf "$COLUMN" "login-docker" "[user][token]" "Run Docker login and create docker config." +printf "$column" "login-docker" "[user][token]" "Run Docker login and create docker config." ``` #### build-image ```bash - printf "$COLUMN" "build-image" "" "Build Docker image with buildx." +printf "$column" "build-image" "" "Build Docker image with buildx." ``` diff --git a/bin/copy-env b/bin/copy-env index 1ef05df..cd1ceaa 100755 --- a/bin/copy-env +++ b/bin/copy-env @@ -1,10 +1,10 @@ -#!/bin/bash +#!/usr/bin/env bash -function copy-env() { - if test -z "$1"; then echo "\$1 is empty."; exit; fi - if test -z "$2"; then echo "\$2 is empty."; exit; fi +copy-env() { + if [[ -z "$1" ]]; then echo "\$1 is empty."; exit; fi + if [[ -z "$2" ]]; then echo "\$2 is empty."; exit; fi TASK_CONFIG_DIR=${TASK_CONFIG_DIR:="$HOME/.config/taskfile.build"} - SOURCE_ENV="$TASK_CONFIG_DIR/.env.$1" - TARGET_ENV="$TASK_CONFIG_DIR/.env.$2" - cp "$SOURCE_ENV" "$TARGET_ENV" + local source_env="$TASK_CONFIG_DIR/.env.$1" + local target_env="$TASK_CONFIG_DIR/.env.$2" + cp "$source_env" "$target_env" } diff --git a/bin/create-nextcloud-env b/bin/create-nextcloud-env index 6bc0871..4dcf68a 100755 --- a/bin/create-nextcloud-env +++ b/bin/create-nextcloud-env @@ -1,19 +1,19 @@ -#!/bin/bash +#!/usr/bin/env bash -function create-nextcloud-env() { - if test -z "$1"; then echo "\$1 is empty."; exit; fi +create-nextcloud-env() { + if [[ -z "$1" ]]; then echo "\$1 is empty."; exit; fi init-config-dir - ENV_FILEPATH="$TASK_CONFIG_DIR/.env.$1" - if [ -f "$ENV_FILEPATH" ]; then - echo "Env file already exists: $ENV_FILEPATH" + local env_filepath="$TASK_CONFIG_DIR/.env.$1" + if [[ -f "$env_filepath" ]]; then + echo "Env file already exists: $env_filepath" exit 1 fi - echo "Init env file: $ENV_FILEPATH" - echo "NEXTCLOUD_URL=" > "$ENV_FILEPATH" - echo "NEXTCLOUD_USERNAME=" >> "$ENV_FILEPATH" - echo "NEXTCLOUD_PASSWORD=" >> "$ENV_FILEPATH" + echo "Init env file: $env_filepath" + echo "NEXTCLOUD_URL=" > "$env_filepath" + echo "NEXTCLOUD_USERNAME=" >> "$env_filepath" + echo "NEXTCLOUD_PASSWORD=" >> "$env_filepath" echo "Edit with: task edit-env $1" } \ No newline at end of file diff --git a/bin/create-odoo-env b/bin/create-odoo-env index 5c274e2..6d5763e 100755 --- a/bin/create-odoo-env +++ b/bin/create-odoo-env @@ -1,20 +1,20 @@ -#!/bin/bash +#!/usr/bin/env bash -function create-odoo-env() { - if test -z "$1"; then echo "\$1 is empty."; exit; fi +create-odoo-env() { + if [[ -z "$1" ]]; then echo "\$1 is empty."; exit; fi init-config-dir - ENV_FILEPATH="$TASK_CONFIG_DIR/.env.$1" - if [ -f "$ENV_FILEPATH" ]; then - echo "Env file already exists: $ENV_FILEPATH" + local env_filepath="$TASK_CONFIG_DIR/.env.$1" + if [[ -f "$env_filepath" ]]; then + echo "Env file already exists: $env_filepath" exit 1 fi - echo "Init env file: $ENV_FILEPATH" - echo "ODOO_URL=$ODOO_URL" > "$ENV_FILEPATH" - echo "ODOO_DATABASE=$ODOO_DATABASE" >> "$ENV_FILEPATH" - echo "ODOO_USERNAME=$ODOO_USERNAME" >> "$ENV_FILEPATH" - echo "ODOO_PASSWORD=$ODOO_PASSWORD" >> "$ENV_FILEPATH" + echo "Init env file: $env_filepath" + echo "ODOO_URL=$ODOO_URL" > "$env_filepath" + echo "ODOO_DATABASE=$ODOO_DATABASE" >> "$env_filepath" + echo "ODOO_USERNAME=$ODOO_USERNAME" >> "$env_filepath" + echo "ODOO_PASSWORD=$ODOO_PASSWORD" >> "$env_filepath" echo "Edit with: task edit-env $1" } \ No newline at end of file diff --git a/bin/edit-env b/bin/edit-env index ee17c7f..7feb9c9 100755 --- a/bin/edit-env +++ b/bin/edit-env @@ -1,8 +1,8 @@ -#!/bin/bash +#!/usr/bin/env bash -function edit-env() { - if test -z "$1"; then echo "\$1 is empty."; exit; fi +edit-env() { + if [[ -z "$1" ]]; then echo "\$1 is empty."; exit; fi TASK_CONFIG_DIR=${TASK_CONFIG_DIR:="$HOME/.config/taskfile.build"} - ENV_FILEPATH="$TASK_CONFIG_DIR/.env.$1" - "$EDITOR" "$ENV_FILEPATH" + local env_filepath="$TASK_CONFIG_DIR/.env.$1" + "$EDITOR" "$env_filepath" } diff --git a/bin/init-config-dir b/bin/init-config-dir index 3b52fd4..725c6e5 100755 --- a/bin/init-config-dir +++ b/bin/init-config-dir @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -function init-config-dir() { +init-config-dir() { echo "Ensure $TASK_CONFIG_DIR exists" mkdir -p "$TASK_CONFIG_DIR" } diff --git a/bin/init-venv b/bin/init-venv index f4699dc..e5bc1da 100755 --- a/bin/init-venv +++ b/bin/init-venv @@ -1,13 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bash -function init-venv() { - if [ ! -d "venv$GIT_BRANCH" ]; then +init-venv() { + if [[ ! -d "venv$GIT_BRANCH" ]]; then echo "Create virtualenv venv$GIT_BRANCH." uv venv "venv$GIT_BRANCH" fi } -function activate-venv() { +activate-venv() { echo "Source virtualenv venv$GIT_BRANCH." source "venv$GIT_BRANCH/bin/activate" } \ No newline at end of file diff --git a/bin/list-env b/bin/list-env index 507261b..bb237f8 100755 --- a/bin/list-env +++ b/bin/list-env @@ -1,27 +1,27 @@ -#!/bin/bash +#!/usr/bin/env bash -function list-env() { +list-env() { TASK_CONFIG_DIR=${TASK_CONFIG_DIR:="$HOME/.config/taskfile.build"} # Define column widths - name_width=20 - file_width=10 + local name_width=20 + local file_width=10 # Print table header printf "| %-${name_width}s | %-${file_width}s |\n" "Name" "Type" echo "|$(printf '%*s' $((name_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((file_width + 2)) '' | tr ' ' '-')|" - for ENV_FILE in "$TASK_CONFIG_DIR"/.env.*; do - if [ -f "$ENV_FILE" ]; then - ENV_NAME="${ENV_FILE##*/}" - ENV_NAME="${ENV_NAME#.env.}" + for env_file in "$TASK_CONFIG_DIR"/.env.*; do + if [[ -f "$env_file" ]]; then + local env_name="${env_file##*/}" + env_name="${env_name#.env.}" - ENV_TYPE="Odoo" - if grep -q "NEXTCLOUD" "$ENV_FILE"; then - ENV_TYPE="Nextcloud" + local env_type="Odoo" + if grep -q "NEXTCLOUD" "$env_file"; then + env_type="Nextcloud" fi - printf "| %-${name_width}s | %-${file_width}s |\n" "$ENV_NAME" "$ENV_TYPE" + printf "| %-${name_width}s | %-${file_width}s |\n" "$env_name" "$env_type" fi done } diff --git a/bin/load-dotenv-from-keepass b/bin/load-dotenv-from-keepass index 965d23e..a14fe03 100755 --- a/bin/load-dotenv-from-keepass +++ b/bin/load-dotenv-from-keepass @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -function load-dotenv-from-keepass { +load-dotenv-from-keepass() { echo "Restore .env file from keepassxc: $KEEPASS_ENTRY" keepassxc-cli attachment-export \ --key-file "$KEEPASS_DATABASE_KEY_FILE" \ diff --git a/bin/load-dotenv-from-pass b/bin/load-dotenv-from-pass index 1a893f8..9723b7c 100755 --- a/bin/load-dotenv-from-pass +++ b/bin/load-dotenv-from-pass @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -function load-dotenv-from-pass() { +load-dotenv-from-pass() { if pass find "$PASS_ENTRY" >/dev/null; then echo "Restore .env file from pass: $PASS_ENTRY" pass show "$PASS_ENTRY" > .env diff --git a/bin/load-env b/bin/load-env index cd91fd4..ec2dbe9 100755 --- a/bin/load-env +++ b/bin/