Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for global justfiles #1648

Closed
spartas opened this issue Jul 18, 2023 · 4 comments · Fixed by #1846
Closed

Support for global justfiles #1648

spartas opened this issue Jul 18, 2023 · 4 comments · Fixed by #1846

Comments

@spartas
Copy link

spartas commented Jul 18, 2023

I'm a recovering Task / Taskfile refugee, who's recently got into just. One of the features of Task that I use extensively is the -g (global) option, which will only search the user's $HOME directory (and no subdirectories) for a Taskfile.

This is very handy for running global tasks or recipes that do not need the current directory context, but it is also useful for running tasks that are somewhat generic, but do need the current directory as context (e.g. docker compose commands that use the services from the current working directory). Obviously this can be replicated in just with something like just $HOME/, but when used with flags and parameters, this quickly becomes unwieldy.

@fordneild
Copy link

if you try a command that isnt in your justfile, iirc just will searching up the file tree looking for one. I have a "global" justfile with general commands at ~/justfile and then project specific commands i put in a justfile at the root of the repository.

@casey
Copy link
Owner

casey commented Jul 21, 2023

This seems reasonable to me, and pretty easy to implement. If you pass --global or -g, it looks for a justfile in ~/.justfile (or maybe ~/justfile or ~/.config/just/justfile)

@spartas
Copy link
Author

spartas commented Jul 21, 2023

fordneild:
if you try a command that isnt in your justfile, iirc just will searching up the file tree looking for one. I have a "global" justfile with general commands at ~/justfile and then project specific commands i put in a justfile at the root of the repository.

I didn't consider that just would continue searching up the tree until it found a match. There are a few things that I do that wouldn't work though.

In my Docker projects, I typically have a default recipe (it's the first recipe in my justfile) that runs docker compose ps. It doesn't make sense to put this (context-specific recipe) in a global justfile, so I also have a default recipe in the global file that runs docker compose ls to list running compose projects across the whole system.

Secondly, I'm often working under mounted filesystems or subtrees that aren't descendants of $HOME.

casey:
This seems reasonable to me, and pretty easy to implement. If you pass --global or -g, it looks for a justfile in ~/.justfile (or maybe ~/justfile or ~/.config/just/justfile)

I don't have a strong opinion about the location for global justfiles (I'd probably use ~/justfile or ~/.config/just/justfile). If you support multiple locations for global justfiles, please document the order of precedence that just will use when searching for these justfiles (it helps when deciding how to override global justfiles on a per-case basis).

Additionally, if you do support ~/.config/just/justfile, please support the $XDG_CONFIG_HOME env var from the XDG Base Directory spec. I don't use these vars myself, but I'm sure that someone will.

@dionjwa
Copy link

dionjwa commented Jul 22, 2023

I have two workarounds for a similar need (although they are not exactly what you are asking for):

This in my ~/.aliases:

alias j='just '
alias .j='just --justfile ~/.justfile --working-directory .'

so j shorthand for normal just and .j for "global" just

And a justfile (in my case renamed backup for its role) but in my $PATH, given executable permissions with the following at the top so that it executes as a command:

#!/usr/bin/env just --justfile

This was referenced Jan 13, 2024
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 a pull request may close this issue.

4 participants