You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/languages.md
+69-1Lines changed: 69 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -360,7 +360,75 @@ Use `system` for tools with special environment requirements that cannot run in
360
360
361
361
`script`runs repository-local scripts without a managed environment. For remote hooks, `entry` is resolved relative to the hook repository root; for local hooks, it is resolved relative to the current working directory.
362
362
363
-
If `entry` contains a newline, it is treated as an inline script. Inline scripts are written to a temporary file and executed based on the script content. If the first line starts with a shebang (`#!`), that interpreter is used (for example, a `pwsh` shebang yields a `.ps1` file). If no shebang is present, `bash` is preferred when available, otherwise `sh` is used.
363
+
#### Inline scripts
364
+
365
+
prek supports **inline scripts** for `language: script`, so you can put a small script directly in `entry`.
366
+
367
+
**How prek decides “inline script” vs “script path”**
368
+
369
+
- If `entry` does *not* contain a newline, it is treated as a normal command/script path.
370
+
- If `entry` *does* contain a newline, it is treated as an inline script **unless** the *first token* resolves to a real file in the repository (or current working directory for `repo: local`).
371
+
372
+
This means YAML block scalars are safe to use for readability even when `entry` is a script path.
373
+
374
+
**How inline scripts are executed**
375
+
376
+
- The inline content is written to a temporary file.
377
+
- If the first line has a shebang (`#!`), prek executes the temp file and lets the OS/shebang decide the interpreter.
378
+
- If there is **no shebang**, prek chooses a default shell:
379
+
- On Unix: prefers `bash -e`, falls back to `sh -e`.
380
+
- On Windows: prefers `pwsh`, then `powershell`, then `cmd.exe`.
381
+
382
+
Any hook arguments (`args`) and selected filenames are passed as arguments to the interpreter/script. For POSIX shells, use `"$@"` to read the filenames; for PowerShell, use `$args`.
383
+
384
+
**Examples**
385
+
386
+
Inline script without a shebang (uses the default shell):
387
+
388
+
```yaml
389
+
repos:
390
+
- repo: local
391
+
hooks:
392
+
- id: inline
393
+
name: inline
394
+
language: script
395
+
entry: |
396
+
echo "hello"
397
+
printf 'args:'
398
+
printf ' %s' "$@"
399
+
printf '\n'
400
+
verbose: true
401
+
```
402
+
403
+
Inline script with a shebang (interpreter comes from the script content):
404
+
405
+
```yaml
406
+
repos:
407
+
- repo: local
408
+
hooks:
409
+
- id: inline-bash
410
+
name: inline-bash
411
+
language: script
412
+
entry: |
413
+
#!/usr/bin/env -S bash -e
414
+
echo "running under bash"
415
+
echo "args: $*"
416
+
verbose: true
417
+
```
418
+
419
+
Multiline `entry`, but still a script path (first token is an existing file):
420
+
421
+
```yaml
422
+
repos:
423
+
- repo: local
424
+
hooks:
425
+
- id: script-path
426
+
name: script-path
427
+
language: script
428
+
entry: |
429
+
./script.sh --from-entry
430
+
pass_filenames: false
431
+
```
364
432
365
433
Use `script` for simple repository scripts that only need file paths and no managed environment.
0 commit comments