From 01c3a74954802f550b3347203b5399cd92e66075 Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Mon, 12 Oct 2026 08:38:42 +0200 Subject: [PATCH] feat: add global flag to create-dotenv and change default storage location - Modify `bin/create-dotenv` to store `.env` files in the current directory by default. - Add `-g` / `--global` flag to store files in `TASK_DOTENV_DIR` instead. - Remove hard-coded `secrets` template special case for path selection; encryption now depends on the filename ending in `secrets.env`. - Update `docs/library.md`, `task.template`, and `prompt.md` to reflect the new behavior and flag. - Verify that `remove-dotenv`, `copy-dotenv`, and `rename-dotenv` correctly handle both local and global paths. --- bin/create-dotenv | 22 ++++++++++++++++------ docs/library.md | 10 ++++------ prompt.md | 43 ++++++++++++++++++++++++++++--------------- task.template | 2 +- 4 files changed, 49 insertions(+), 28 deletions(-) diff --git a/bin/create-dotenv b/bin/create-dotenv index cd46533..f9d258c 100755 --- a/bin/create-dotenv +++ b/bin/create-dotenv @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + create-dotenv() { if [[ -z "$1" ]]; then echo "\$1/env is empty." @@ -8,6 +10,11 @@ create-dotenv() { return 1 fi + local global_flag=false + if [[ "$3" == "-g" || "$3" == "--global" ]]; then + global_flag=true + fi + local env_name="$1" local template="$2" local env_filename="${env_name}.env" @@ -20,15 +27,18 @@ create-dotenv() { fi local env_filepath - if [[ "$template" == "secrets" ]]; then + if [[ "$global_flag" == true ]]; then + init-dotenv-dir + env_filepath="$TASK_DOTENV_DIR/$env_filename" + else + env_filepath="$PWD/$env_filename" + fi + + if [[ "$env_filename" == *secrets.env ]]; then if [[ ! -f ".sops.yaml" ]]; then echo "Error: .sops.yaml not found. Run init-dotenv-sops first." return 1 fi - env_filepath="$env_filename" - else - init-dotenv-dir - env_filepath="$TASK_DOTENV_DIR/$env_filename" fi if [[ -f "$env_filepath" ]]; then @@ -39,7 +49,7 @@ create-dotenv() { echo "Init .env file: $env_filepath" cp "$template_file" "$env_filepath" - if [[ "$template" == "secrets" ]]; then + if [[ "$env_filename" == *secrets.env ]]; then if ! sops --encrypt --in-place "$env_filepath"; then echo "Encryption failed; removing $env_filepath" rm -f "$env_filepath" diff --git a/docs/library.md b/docs/library.md index e67016d..66129c4 100644 --- a/docs/library.md +++ b/docs/library.md @@ -201,7 +201,7 @@ Secrets files ending in `secrets.env` are encrypted with [sops](https://getsops. ### create-dotenv ```bash -rows+=("create-dotenv|