I often want to use the directory of where the Taskfile is located as an input to other commands (not the current working directory), but it seems like sprig really locks down access to the filesystem.
Is this possible to do with Task as a first-class idea?
For example, something like:
tasks:
show-current-dir:
desc: "show where Task is executing from"
cmds:
- echo {{ .TASKFILE_LOCATION }}
Note that this isn't the same as just using $PWD or -d because the working directory might be different; Task should probably provide this as a first-class feature if it doesn't already.
Hi @fj,
You should actually be fine using pwd if you haven't specified another dir: or your haven't cded in the command.
Otherwise, yeah, I think it makes sense to a have variable with the Taskfile location.
Actually, could be handy for when Taskfiles are imported as well.
Example use-case:
root/Taskfile.yaml:
version: "2.X"
includes:
sub: sub/Tasks.yaml
tasks:
default:
cmds:
- sub:test
root/sub/Tasks.yaml:
version: "2.X"
tasks:
test:
dir: "{{.TASKFILE_DIR}}"
cmds:
- ./bin/executable
root/sub/bin/executable
#!/bin/sh
echo "Hello World"
Just stumbled upon this exact issue. I guess a workaround for now is manually setting the dir to the respective folder. The negative side-effect: The Taskfile in the subfolder can no longer be used independently.
Most helpful comment
Example use-case:
root/Taskfile.yaml:
root/sub/Tasks.yaml:
root/sub/bin/executable