Skip to content

feat: Add env var TASK_INIT_DIR to specify a custom --init template#2814

Open
B13rg wants to merge 2 commits intogo-task:mainfrom
B13rg:init-env-var
Open

feat: Add env var TASK_INIT_DIR to specify a custom --init template#2814
B13rg wants to merge 2 commits intogo-task:mainfrom
B13rg:init-env-var

Conversation

@B13rg
Copy link
Copy Markdown

@B13rg B13rg commented Apr 26, 2026

This pr adds an additional environment variable TASK_INIT_DIR, which specifies a directory or file to use with the --init command. Task will copy the Taskfile from this location instead of using the embedded template.

This should allow for simple init customization via .bashrc and more.

Related issue: #2012

Assisted by Claude Opus 4.5

Testing

Various tests showing operation

Default behavior with no configuration
~/github/go-task--task/dist/go-task--task_linux_amd64_v1
> pwd                                                                         
/home/b13rg/github/go-task--task/dist/go-task--task_linux_amd64_v1

~/github/go-task--task/dist/go-task--task_linux_amd64_v1
> cat ./example/Taskfile.yml           
# https://taskfile.dev

version: '3'

vars:
  RESPONSE: The World says hello!

tasks:
  default:
    cmds:
      - echo "{{.RESPONSE}}"
    silent: true

~/github/go-task--task/dist/go-task--task_linux_amd64_v1
> TASK_INIT_DIR= ./task --init ; cat ./Taskfile.yml; rm ./Taskfile.yml 
Taskfile created: Taskfile.yml
# yaml-language-server: $schema=https://taskfile.dev/schema.json

version: '3'

vars:
  GREETING: Hello, world!

tasks:
  default:
    desc: Print a greeting message
    cmds:
      - echo "{{.GREETING}}"
    silent: true
Specify directory path
> TASK_INIT_DIR=$(pwd)/example ./task --init ; cat ./Taskfile.yml; rm ./Taskfile.yml 
Taskfile created: Taskfile.yml
# https://taskfile.dev

version: '3'

vars:
  RESPONSE: The World says hello!

tasks:
  default:
    cmds:
      - echo "{{.RESPONSE}}"
    silent: true
Specify complete file path
 ~/github/go-task--task/dist/go-task--task_linux_amd64_v1
> TASK_INIT_DIR=$(pwd)/example/Taskfile.yml ./task --init ; cat ./Taskfile.yml; rm ./Taskfile.yml
Taskfile created: Taskfile.yml
# https://taskfile.dev

version: '3'

vars:
  RESPONSE: The World says hello!

tasks:
  default:
    cmds:
      - echo "{{.RESPONSE}}"
    silent: true
Specify local directory path
 ~/github/go-task--task/dist/go-task--task_linux_amd64_v1
> TASK_INIT_DIR=./example/Taskfile.yml ./task --init ; cat ./Taskfile.yml; rm ./Taskfile.yml
Taskfile created: Taskfile.yml
# https://taskfile.dev

version: '3'

vars:
  RESPONSE: The World says hello!

tasks:
  default:
    cmds:
      - echo "{{.RESPONSE}}"
    silent: true
Specify path from `~` directory
 ~/github/go-task--task/dist/go-task--task_linux_amd64_v1
> TASK_INIT_DIR=~/github/go-task--task/dist/go-task--task_linux_amd64_v1/example/Taskfile.yml ./task --init ; cat ./Taskfile.yml; rm ./Taskfile.yml 
Taskfile created: Taskfile.yml
# https://taskfile.dev

version: '3'

vars:
  RESPONSE: The World says hello!

tasks:
  default:
    cmds:
      - echo "{{.RESPONSE}}"
    silent: true
Export env var before using
 ~/github/go-task--task/dist/go-task--task_linux_amd64_v1
> export TASK_INIT_DIR=~/github/go-task--task/dist/go-task--task_linux_amd64_v1/example/Taskfile.yml;
> ./task --init ; cat ./Taskfile.yml; rm ./Taskfile.yml
Taskfile created: Taskfile.yml
# https://taskfile.dev

version: '3'

vars:
  RESPONSE: The World says hello!

tasks:
  default:
    cmds:
      - echo "{{.RESPONSE}}"
    silent: true

@B13rg B13rg marked this pull request as ready for review April 26, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant