just icon indicating copy to clipboard operation
just copied to clipboard

OS-specific attributes on all top-level declarations

Open cspotcode opened this issue 3 months ago • 0 comments

Is it intuitive to support OS-specific attributes on all top-level declarations in a justfile, not just recipes?

The OS is hardcoded into the executable, so the logic is straightforward:

E.g just.exe parses and completely ignores anything with [macos] or [linux] on it

This simplifies things overall and implements multiple tickets:

  • set windows-shell := can be deprecated, replaced by [windows] ; set shell :=
  • Get windows-script-interpreter for free, can close #2944
  • Implements #1493 & #2627
  • Implements #2786
  • Replace conditional variable declarations:
    • SHEBANG := if os() == 'windows' {
          'busybox sh'
      } else {
          '/usr/bin/env sh'
      }
      recipe:
        #!{{SHEBANG}}
    • becomes:
      [windows]
      SHEBANG := 'busybox sh'
      [unix]
      SHEBANG := '/usr/bin/env sh'
      
      recipe:
        #!{{SHEBANG}}

Design challenges

Requires OS-specific attribute on both windows and unix setting/variable declarations:

[unix] # <-- if you omit this, error "Setting redefined"
set shell := ['bash', '-euc']

[windows]
set shell := ['busybox', 'bash', '-euc']

We should raise the "redefinition" error on Unix, too. Even though we're ignoring the second declaration on Unix, the error warns us that this justfile will fail on Windows.

Alternatively, could allow redefinition if second one has OS attribute. The un-attributed declaration becomes automatically [not-windows].

Limitations

Falls short of enabling if {} else {} logic in settings. But that's currently impossible anyway.

# If anyone has been wanting to do this, they still won't be able to
if which('sh') {
    set shell := ['sh', '-euc']
} else {
    set shell := ['somethingelse', '-euc']
}

cspotcode avatar Nov 17 '25 01:11 cspotcode