Skip to content

Commit 5292fea

Browse files
authored
feat(pre-commit): add prek support (ohmyzsh#13529)
Closes ohmyzsh#13432
1 parent 4f8632d commit 5292fea

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

plugins/pre-commit/README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Pre-commit plugin
22

33
This plugin adds aliases for common commands of [pre-commit](https://pre-commit.com/).
4+
It also supports [prek](https://github.com/prek/prek) as a drop-in replacement.
5+
If `prek` is available, it will be used; otherwise, `pre-commit` is used as fallback.
46

57
To use this plugin, add it to the plugins array in your zshrc file:
68

@@ -10,10 +12,11 @@ plugins=(... pre-commit)
1012

1113
## Aliases
1214

13-
| Alias | Command | Description |
14-
| ------- | -------------------------------------- | ------------------------------------------------------ |
15-
| prc | `pre-commit` | The `pre-commit` command |
16-
| prcau | `pre-commit autoupdate` | Update hooks automatically |
17-
| prcr | `pre-commit run` | The `pre-commit run` command |
18-
| prcra | `pre-commit run --all-files` | Run pre-commit hooks on all files |
19-
| prcrf | `pre-commit run --files` | Run pre-commit hooks on a given list of files |
15+
| Alias | Command | Description |
16+
| ----- | ------------------------------------------------------ | --------------------------------------------- |
17+
| prc | `prek` or `pre-commit` | The pre-commit command |
18+
| prcau | `prek auto-update` or `pre-commit autoupdate` | Update hooks automatically |
19+
| prcr | `prek run` or `pre-commit run` | The pre-commit run command |
20+
| prcra | `prek run --all-files` or `pre-commit run --all-files` | Run pre-commit hooks on all files |
21+
| prcrf | `prek run --files` or `pre-commit run --files` | Run pre-commit hooks on a given list of files |
22+

plugins/pre-commit/pre-commit.plugin.zsh

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
# Aliases for pre-commit
2-
alias prc='pre-commit'
1+
# Aliases for pre-commit (uses prek if available, else pre-commit)
2+
if command -v prek &> /dev/null; then
3+
_prc_cmd='prek'
4+
_prc_autoupdate='auto-update'
5+
else
6+
_prc_cmd='pre-commit'
7+
_prc_autoupdate='autoupdate'
8+
fi
39

4-
alias prcau='pre-commit autoupdate'
10+
alias prc="$_prc_cmd"
11+
12+
alias prcau="$_prc_cmd $_prc_autoupdate"
13+
14+
alias prcr="$_prc_cmd run"
15+
alias prcra="$_prc_cmd run --all-files"
16+
alias prcrf="$_prc_cmd run --files"
517

6-
alias prcr='pre-commit run'
7-
alias prcra='pre-commit run --all-files'
8-
alias prcrf='pre-commit run --files'

0 commit comments

Comments
 (0)