just icon indicating copy to clipboard operation
just copied to clipboard

Treat paths in submodule relative to directory of root `.justfile`

Open Splines opened this issue 1 year ago • 4 comments

It'd be great to have an option to treat all paths in a submodule relative to the directory containing the root .justfile. I think I'd prefer a per-module flag for this instead of a global one.

This would allow me to let my submodules reside in other file locations (e.g. in a folder .config/commands/), while not having to issue a cd {{justfile_directory()}} or cd ../../ at the beginning of every recipe.

Splines avatar Jul 04 '24 23:07 Splines

I think this would be great. I can imagine a few options that might be useful:

  1. Use the working directory of the root justfile
  2. Use the working directory of the parent module, even if it isn't the root.
  3. Use a specific working directory

The syntax could be:

# default value
set working-dir := default
set working-dir := self

# use the working directory of the parent module
set working-dir := parent

# use the working directory of the root justfile
set working-dir := root

# use some other working directory
set working-dir := "some/other/directory"

casey avatar Jul 05 '24 00:07 casey

This is probably related to #2273 and the respective PR #2283.

Splines avatar Aug 01 '24 10:08 Splines

#2283 added support for the form that takes a string:

set working-dir := "some/other/directory"

So we're still lacking the ability to use the working directory of a parent justfile.

I think the best syntax for using the working directory of the parent is:

set working-dir := super

However, I'd like to keep the door open for eventually allowing the use of a variable. I.e.:

set working-dir := foo

just currently doesn't allow the use of variables in settings, since settings may affect how backticks and the shell(…) function run, including their working directory and exported variables.

So, this syntax:

set working-dir := super

Would change meaning if the RHS of a setting became an expression:

super := "hello"
set working-dir := super

One option is to use some kind of syntax which isn't a valid expression:

set working-dir := @super
set working-dir := super.working_dir
set working-dir := super::working_dir
set working-dir := super->working_dir
set working-dir := super#working_dir
set working-dir := super@working_dir

This is a bit wonky, but the fact that expressions can't be used in setting values has been an issue many times, so I wouldn't want to preclude fixing it.

casey avatar Aug 01 '24 19:08 casey

This is all horrifically complicated by the fact that variables, recipes, and settings can all have the same name.

casey avatar Aug 01 '24 19:08 casey