@chewygumxx/skill-configuring-mise-tasks 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md CHANGED
@@ -2,11 +2,11 @@
2
2
  name: configuring-mise-tasks
3
3
  description: >-
4
4
  Sets out a repository's standard mise tasks: where each action is
5
- defined, how tasks are written and named, how they narrow to staged
6
- files, and how hooks run them. Use when adding, changing, reviewing or
7
- adopting a repository's mise tasks, deciding what belongs in
8
- package.json scripts or the runtime's equivalent, or running git hooks
9
- or worktree hooks through mise.
5
+ defined, how tasks are written and named, how they hand work to the
6
+ tools made for it, and how hooks run them. Use when adding, changing,
7
+ reviewing or adopting a repository's mise tasks, deciding what belongs
8
+ in package.json scripts or the runtime's equivalent, or running git
9
+ hooks or worktree hooks through mise.
10
10
  license: GPL-3.0-only
11
11
  ---
12
12
 
@@ -21,8 +21,26 @@ license: GPL-3.0-only
21
21
 
22
22
  Repositories offer the same tasks under the same names, written the
23
23
  same way, so `mise run check` means one thing everywhere. Here is where an
24
- action is defined, how tasks are written and named, how a task narrows to
25
- staged files, and how hooks reach it.
24
+ action is defined, how tasks are written and named, how they hand work to
25
+ the tools made for it, and how hooks reach them.
26
+
27
+ ## mise as the switchboard
28
+
29
+ mise is a repository's switchboard: it pins the tools, sets the
30
+ environment, and names the tasks a developer or agent runs. A task does
31
+ none of the work itself. It hands it to the tool made for it, and adds no
32
+ logic the tool already has:
33
+
34
+ | Work | Tool |
35
+ | -------------------------------------------- | ------------------------------------ |
36
+ | Linting, formatting, file selection, caching | [hk](https://hk.jdx.dev) |
37
+ | Git worktrees | worktrunk |
38
+ | Workspaces and agent delegation | herdr |
39
+ | Agent skill sync | `@vercel-labs/skills-cli` |
40
+ | CI, locally | act |
41
+
42
+ So a task never selects files, stashes edits or caches results for a tool
43
+ that does so itself: `lint` is `hk check`, not a list of linters.
26
44
 
27
45
  ## mise or the runtime
28
46
 
@@ -61,8 +79,20 @@ Remove any other entry, and change its mentions from `bun run <name>` to
61
79
  ```
62
80
 
63
81
  The include path is relative to the repository root. mise 2026.11.6
64
- takes a glob there. Task templates go in this file too, as an
65
- included task file holds tasks alone.
82
+ takes a glob there.
83
+
84
+ - The task templates come from
85
+ [`@chewygumxx/mise-tasks-config`](https://www.npmjs.com/package/@chewygumxx/mise-tasks-config),
86
+ linked into `.config/mise/conf.d/`, as an included task file holds tasks
87
+ alone and mise reads templates from a configuration file:
88
+
89
+ ```sh
90
+ bun add --dev --exact @chewygumxx/mise-tasks-config @chewygumxx/hk-config
91
+ ln -s ../../../node_modules/@chewygumxx/mise-tasks-config/tasks.toml .config/mise/conf.d/50-cgxx.toml
92
+ ```
93
+
94
+ Pin both exactly: below 1.0.0, each functional change to them is a
95
+ breaking one.
66
96
 
67
97
  - `.config/mise/tasks/` holds every task, as TOML, one file per task
68
98
  family, so a task is found by the first part of its name:
@@ -82,18 +112,27 @@ Remove any other entry, and change its mentions from `bun run <name>` to
82
112
  The runtime's file is named for it, such as `bun.task.toml`, and holds
83
113
  `dev`, `start` and `build` and any task that runs one of its scripts,
84
114
  such as `eval` or `skills`. Each file opens with the house header
85
- naming its own path, as the [templates](assets/tasks/) do. Leave out a
115
+ naming its own path, as the [examples](assets/tasks/) do. Leave out a
86
116
  file with no tasks.
87
117
 
118
+ - Each standard task extends its `cgxx:` template and sets only what
119
+ differs, such as `test`'s `run`. A task's own field replaces the
120
+ template's; `extends` names a template, never another task.
121
+
88
122
  - A task's `run` is one line, or a short list of one-line commands.
89
123
  Anything longer is a script in `scripts/`, which runs without mise. No
90
124
  file tasks with `#MISE` comments.
91
125
  - Every task has a `description`, which `mise tasks` shows. Otherwise a
92
126
  task file carries labels, and at most a one-line why where a setting is
93
127
  not obvious. Longer reasoning goes in the directory's guidance file.
94
- - Tools mise pins run by name. Tools the runtime installs run through it:
95
- `bunx --bun --no-install <cli>` for Bun, as `mise run` gives neither
96
- `node_modules/.bin` on `PATH` nor `bun run`'s Bun-as-node.
128
+ - Tools mise pins run by name. Tools the runtime installs run through it,
129
+ as `mise run` puts no `node_modules/.bin` on `PATH`: `bun run <cli>` for
130
+ Bun, with `[run] bun = true` in `bunfig.toml`, so a CLI whose shebang
131
+ names `node` runs on Bun. `bun run` never installs, and a
132
+ `package.json` script of the CLI's name runs in its place, so name no
133
+ script after a CLI. Not `bunx`, which runs such a CLI on Node without
134
+ `--bun`, and without `--no-install` fetches the package named for the
135
+ CLI, which need not be the one locked.
97
136
 
98
137
  ## The standard set
99
138
 
@@ -108,16 +147,17 @@ Remove any other entry, and change its mentions from `bun run <name>` to
108
147
  Where they apply, `dev`, `start` and `build` too, wrapping the runtime's
109
148
  own entry points, and `act`, which runs CI locally.
110
149
 
111
- - Sub-tasks are named for their parent and their kind: `lint:md`,
112
- `format:toml`, `lint:types`. The parent depends on each, and mise runs
113
- them in parallel.
150
+ - Linters and formatters are hk steps, not tasks: `lint` and `format` run
151
+ every step, and `-S <step>` one, as `mise run lint -S tombi`.
152
+ - Any other sub-task is named for its parent and its kind, such as
153
+ `lint:commit`.
114
154
  - `test:<subject>` tasks, each running one test file to record what it
115
155
  covers for `mise tasks` and `mise mcp`, are not sub-tasks: `test` never
116
156
  depends on a `test:<subject>`, as it runs every test itself and would
117
157
  then run each twice.
118
- - A format check is a lint: `lint:toml` checks formatting as well as
119
- linting, so `format` only ever writes.
120
- - Only the five parents take aliases.
158
+ - A format check is a lint: the `tombi` step checks formatting as well
159
+ as linting, so `format` only ever writes.
160
+ - Only the five parents take aliases, which their templates carry.
121
161
  - `lint`, `test` and `check` never write files; CI and the pre-commit
122
162
  hook rely on that.
123
163
  - `lint:commit` takes the commit message file as an argument, so `lint`
@@ -125,87 +165,71 @@ own entry points, and `act`, which runs CI locally.
125
165
  - A task outside the set takes a name that cannot be mistaken for one in
126
166
  it, such as `commit` or `skills`.
127
167
 
128
- To adopt the set, copy the three files in [`assets/tasks/`](assets/tasks/)
129
- to `.config/mise/tasks/`, point each header at its new path and fill in
130
- the placeholders, merge [`assets/config.toml`](assets/config.toml) into
131
- `.config/mise/config.toml`, and copy
132
- [`scripts/with-files.sh`](scripts/with-files.sh) to `scripts/`. A
133
- repository with a single `.config/mise/tasks.toml` moves each task into
134
- its family's file and changes the include to the glob.
168
+ To adopt the set, add the two packages and the link above, copy the
169
+ files in [`assets/tasks/`](assets/tasks/) to `.config/mise/tasks/`, pointing
170
+ each header at its new path and filling in `test`'s `run`, merge
171
+ [`assets/config.toml`](assets/config.toml) into `.config/mise/config.toml`,
172
+ and copy [`assets/hk.pkl`](assets/hk.pkl) to `.config/hk.pkl`. A repository
173
+ with a single `.config/mise/tasks.toml` moves each task into its family's
174
+ file and changes the include to the glob.
135
175
 
136
- ## Staged by default
176
+ ## Selecting files
137
177
 
138
- Every file-based task, and `lint`, `format` and `check`, act on the
139
- staged files of their kind alone, and with `--all`, on every tracked
140
- file of their kind. Two task templates in `.config/mise/config.toml`
141
- declare the switch once:
178
+ hk selects the files `lint`, `format` and `check` act on:
142
179
 
143
- ```toml
144
- [task_templates.staged]
145
- usage = '''
146
- flag "--staged" negate="--all" default=#true {
147
- help "Act on staged files alone, or every file with --all"
148
- }
149
- '''
150
- ```
180
+ | Flag | Files |
181
+ | ---------- | -------------------------------------------------------- |
182
+ | None | The changed files: staged, unstaged and untracked |
183
+ | `--staged` | The staged files alone |
184
+ | `--all` | Every file git does not ignore, untracked ones included |
151
185
 
152
- `staged:cached` adds the `sources` and `outputs` that let a check
153
- [skip unchanged work](#skipping-unchanged-work). A file-based check
154
- extends it; `lint`, `format`, `check` and each formatter extend
155
- `staged`. Both are in [`assets/config.toml`](assets/config.toml).
186
+ The templates declare the flags, and `cgxx-hk` passes them on as hk's own,
187
+ so no `run` names a file. `check` forwards its flag to `lint` through a
188
+ templated `depends`. A change to a path in `$CGXX_WIDEN_ON`, by default
189
+ `bun.lock`, `.config/hk.pkl` and `.config/mise`, selects every file, as it
190
+ can change the result for any of them. A repository whose own files
191
+ configure its linters adds them in mise's `[env]`:
156
192
 
157
193
  ```toml
158
- ["lint:md"]
159
- description = "Lint Markdown with <linter>"
160
- extends = "staged:cached"
161
- run = "scripts/with-files.sh '*.md' -- <command>"
194
+ [env]
195
+ CGXX_WIDEN_ON = "bun.lock .config packages"
162
196
  ```
163
197
 
164
- mise exports the flag to the run as `$usage_staged`, which
165
- `scripts/with-files.sh` reads, so no `run` names the flag. A script of
166
- your own reads it alike, testing for `true`: under `--all` it is `false`,
167
- not unset. A template's `vars` and `env` cannot carry the choice instead,
168
- as mise renders them before it parses the flag.
198
+ Every step runs, however many fail, and `format` leaves its fixes
199
+ unstaged for review.
169
200
 
170
- A parent forwards `--all` alone through a templated `depends`, its
171
- dependencies being staged already:
201
+ ## Skipping unchanged work
172
202
 
173
- ```toml
174
- depends = ['lint {% if not usage.staged %}--all{% endif %}', "test"]
175
- ```
203
+ Each step of `@chewygumxx/hk-config` sets hk's `cache`, keyed on its
204
+ `cache_inputs`: the files it reads, its configuration, `bun.lock` and
205
+ `.config/mise/config.toml`. hk skips a step whose inputs have not changed
206
+ since it last passed. hk leaves files git ignores out of the key, so a
207
+ configuration package in `node_modules` counts through `bun.lock`; a
208
+ repository that keeps its own copies amends the steps' `extraInputs`, as
209
+ [`assets/hk.pkl`](assets/hk.pkl) shows.
176
210
 
177
- A task that cannot narrow to files, such as the type check or the tests,
178
- takes no flag, declares no `sources`, and checks everything on every run.
211
+ No task declares `sources`: hk's cache does the work.
179
212
 
180
- ## Skipping unchanged work
213
+ ## hk steps
181
214
 
182
- Each checking task that reads particular files takes `sources`, the
183
- files it reads and the configuration that governs them, the lockfile and
184
- the tool pins in `.config/mise/config.toml` among it, and
185
- `outputs = { auto = true }`, from `staged:cached`. mise then skips it when
186
- nothing changed since it last passed.
215
+ `.config/hk.pkl` imports the steps from node_modules and maps them into
216
+ hk's `check` and `fix` hooks, which `lint` and `format` run:
187
217
 
188
- - mise keeps a record per set of arguments, so a staged pass never lets
189
- an `--all` run skip.
190
- - A staged run also takes git's index as a source, by its absolute
191
- path, inside the task. A task with `sources` of its own replaces the
192
- template's, so lists the index too. [Staged runs](./references/staged-runs.md)
193
- says why each is so:
218
+ ```pkl
219
+ import "../node_modules/@chewygumxx/hk-config/steps.pkl" as cgxx
194
220
 
195
- ```toml
196
- sources = [
197
- "**/*.md",
198
- "!node_modules/**",
199
- "bun.lock",
200
- ".config/mise/config.toml",
201
- '{% if usage.staged %}{{ exec(command="git rev-parse --path-format=absolute --git-path index") }}{% endif %}',
202
- ]
203
- ```
221
+ hooks {
222
+ ["check"] { steps = cgxx.lint }
223
+ ["fix"] {
224
+ stage = false
225
+ steps = cgxx.format
226
+ }
227
+ }
228
+ ```
204
229
 
205
- - mise does not read `.gitignore`: a file written anywhere a source glob
206
- reaches, ignored or not, makes the task rerun. Exclude `node_modules`.
207
- - `mise run --force check` runs everything regardless; mise's own flags
208
- go before the task's name.
230
+ `cgxx.lint` maps every step and `cgxx.format` those that fix, as `hk fix`
231
+ runs a step's check where it has no fix. Amend a mapping to change a step
232
+ or add one of the repository's own, or map single steps by name.
209
233
 
210
234
  ## Hooks
211
235
 
@@ -216,12 +240,19 @@ A git hook is one step, calling a task, whichever manager runs it:
216
240
  `{{ commit_msg_file }}` in hk's `hk.pkl`, or `"$1"` in a shell hook
217
241
 
218
242
  In `hk.pkl`, such a step is a `check` command alone, with no `glob`: the
219
- task picks its own files. Pin hk among mise's tools, and install its
220
- hooks from mise's config, so `mise install` sets them up:
243
+ task picks its own files, running hk's hooks in turn inside the stash the
244
+ pre-commit hook made. Pin hk among mise's tools, and install its hooks
245
+ from mise's config, so `mise install` sets them up.
246
+
247
+ Until the packages are installed no task loads, as each extends a
248
+ template that does not yet exist, and `hk.pkl` cannot import its steps.
249
+ So `mise install` installs the packages before the hooks. CI installs the
250
+ packages itself, from a lockfile a release may yet refresh, and needs no
251
+ hooks:
221
252
 
222
253
  ```toml
223
254
  [hooks]
224
- postinstall = "hk install --mise"
255
+ postinstall = 'test -n "${CI-}" || { bun ci && hk install --mise; }'
225
256
  ```
226
257
 
227
258
  Worktree tools' hooks, such as worktrunk's in `.config/wt.toml`, call
@@ -254,6 +285,7 @@ finds no config to refuse.
254
285
 
255
286
  `act`, and any CI task that depends on a remote script, are the one
256
287
  exception to TOML-only tasks. Read [Remote tasks](./references/remote-tasks.md)
257
- before adding one.
288
+ before adding one; `act` extends `cgxx:act`, which runs the repository's
289
+ own hidden remote task.
258
290
 
259
291
  <!-- vim:set expandtab shiftwidth=2 filetype=markdown foldlevel=3: -->
@@ -11,28 +11,12 @@
11
11
 
12
12
  #
13
13
  # Merged into .config/mise/config.toml: the task files' include, and the
14
- # templates their file-based tasks extend, as a task file holds tasks alone.
14
+ # install order the hooks need. The templates come from
15
+ # @chewygumxx/mise-tasks-config, linked into .config/mise/conf.d/.
15
16
  #
16
17
 
18
+ [hooks]
19
+ postinstall = 'test -n "${CI-}" || { bun ci && hk install --mise; }'
20
+
17
21
  [task_config]
18
22
  includes = [ ".config/mise/tasks/*.task.toml" ]
19
-
20
- [task_templates.staged]
21
- usage = '''
22
- flag "--staged" negate="--all" default=#true {
23
- help "Act on staged files alone, or every file with --all"
24
- }
25
- '''
26
-
27
- [task_templates."staged:cached"]
28
- usage = '''
29
- flag "--staged" negate="--all" default=#true {
30
- help "Act on staged files alone, or every file with --all"
31
- }
32
- '''
33
- sources = [
34
- "**/*",
35
- "!node_modules/**",
36
- "{% if usage.staged %}{{ exec(command=\"git rev-parse --path-format=absolute --git-path index\") }}{% endif %}"
37
- ]
38
- outputs = { auto = true }
package/assets/hk.pkl ADDED
@@ -0,0 +1,50 @@
1
+ // vim:set expandtab shiftwidth=4 filetype=pkl:
2
+ // SPDX-License-Identifier: GPL-3.0-only
3
+
4
+ //
5
+ //
6
+ // ~chewygumxx/agentic-library.git
7
+ // ::: :/skills/configuring-mise-tasks/assets/hk.pkl
8
+ //
9
+ //
10
+
11
+ //
12
+ // Copied to .config/hk.pkl, its own path above changed to match.
13
+ //
14
+
15
+ amends "package://github.com/jdx/hk/releases/download/v2.13.0/hk@2.13.0#/Config.pkl"
16
+
17
+ import "../node_modules/@chewygumxx/hk-config/steps.pkl" as shared
18
+
19
+ // Steps also rerun when these change, such as a repository's own copies of
20
+ // the configuration packages.
21
+ local cgxx = (shared) {
22
+ extraInputs = List()
23
+ }
24
+
25
+ hooks {
26
+ ["check"] {
27
+ steps = cgxx.lint
28
+ }
29
+ ["fix"] {
30
+ stage = false
31
+ steps = cgxx.format
32
+ }
33
+ ["pre-commit"] {
34
+ stash = "git"
35
+ fix = false
36
+ stage = false
37
+ steps {
38
+ ["check"] {
39
+ check = "mise run check --staged"
40
+ }
41
+ }
42
+ }
43
+ ["commit-msg"] {
44
+ steps {
45
+ ["commitlint"] {
46
+ check = "mise run lint:commit \"{{ commit_msg_file }}\""
47
+ }
48
+ }
49
+ }
50
+ }
@@ -11,17 +11,8 @@
11
11
 
12
12
  #
13
13
  # Copied to .config/mise/tasks/format.task.toml, its own path above
14
- # changed to match. Replace each <...>, and repeat format:<kind> once per
15
- # kind of file.
14
+ # changed to match.
16
15
  #
17
16
 
18
17
  [format]
19
- description = "Apply every formatter"
20
- alias = "f"
21
- extends = "staged"
22
- depends = [ "format:<kind> {% if not usage.staged %}--all{% endif %}" ]
23
-
24
- ["format:<kind>"]
25
- description = "Format <kind> files with <formatter>"
26
- extends = "staged"
27
- run = "scripts/with-files.sh '*.<ext>' -- <formatter, writing>"
18
+ extends = "cgxx:format"
@@ -11,45 +11,11 @@
11
11
 
12
12
  #
13
13
  # Copied to .config/mise/tasks/lint.task.toml, its own path above
14
- # changed to match. Replace each <...>, and repeat lint:<kind> once per
15
- # kind of file.
14
+ # changed to match.
16
15
  #
17
16
 
18
17
  [lint]
19
- description = "Run every linter and format check"
20
- alias = "l"
21
- extends = "staged"
22
- depends = [
23
- "lint:<kind> {% if not usage.staged %}--all{% endif %}",
24
- "lint:types",
25
- ]
26
-
27
- # --------------------
28
- # Lint: file by file
29
- # --------------------
30
-
31
- ["lint:<kind>"]
32
- description = "Lint <kind> files with <linter>"
33
- extends = "staged:cached"
34
- sources = [
35
- "**/*.<ext>",
36
- "!node_modules/**",
37
- "<linter config>",
38
- "<lockfile>",
39
- ".config/mise/config.toml",
40
- "{% if usage.staged %}{{ exec(command=\"git rev-parse --path-format=absolute --git-path index\") }}{% endif %}"
41
- ]
42
- run = "scripts/with-files.sh '*.<ext>' -- <linter, check only>"
43
-
44
- # ---------------------
45
- # Lint: whole project
46
- # ---------------------
47
-
48
- ["lint:types"]
49
- description = "Type-check with <type checker>"
50
- run = "<type checker>"
18
+ extends = "cgxx:lint"
51
19
 
52
20
  ["lint:commit"]
53
- description = "Lint a commit message file with <commit linter>"
54
- usage = 'arg "<file>" help="The commit message file"'
55
- run = '<commit linter> "$usage_file"'
21
+ extends = "cgxx:lint:commit"
@@ -15,17 +15,11 @@
15
15
  #
16
16
 
17
17
  [install]
18
- description = "Install the locked dependency tree"
19
- alias = "i"
20
- run = "<locked install, such as bun ci>"
18
+ extends = "cgxx:install"
21
19
 
22
20
  [test]
23
- description = "Run the tests"
24
- alias = "t"
25
- run = "<test command>"
21
+ extends = "cgxx:test"
22
+ run = "<test command>"
26
23
 
27
24
  [check]
28
- description = "Run everything CI runs: lint and test"
29
- alias = "c"
30
- extends = "staged"
31
- depends = [ "lint {% if not usage.staged %}--all{% endif %}", "test" ]
25
+ extends = "cgxx:check"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chewygumxx/skill-configuring-mise-tasks",
3
- "version": "0.0.2",
4
- "description": "Sets out a repository's standard mise tasks: where each action is defined, how tasks are written and named, how they narrow to staged files, and how hooks run them. Use when adding, changing, reviewing or adopting a repository's mise tasks, deciding what belongs in package.json scripts or the runtime's equivalent, or running git hooks or worktree hooks through mise.",
3
+ "version": "0.1.0",
4
+ "description": "Sets out a repository's standard mise tasks: where each action is defined, how tasks are written and named, how they hand work to the tools made for it, and how hooks run them. Use when adding, changing, reviewing or adopting a repository's mise tasks, deciding what belongs in package.json scripts or the runtime's equivalent, or running git hooks or worktree hooks through mise.",
5
5
  "keywords": [
6
6
  "agent-skills"
7
7
  ],
@@ -15,8 +15,7 @@
15
15
  "files": [
16
16
  "SKILL.md",
17
17
  "assets",
18
- "references",
19
- "scripts"
18
+ "references"
20
19
  ],
21
20
  "scripts": {
22
21
  "prepack": "cp ../../LICENSE LICENSE",
@@ -10,12 +10,12 @@
10
10
  The one exception to TOML-only tasks: `act`, and any CI task that depends on
11
11
  a remote script referenced by a tag and fetched uncached. Such a task is
12
12
  a hidden remote file task, run by a visible wrapper that fetches it
13
- afresh each time, both in `other.task.toml`:
13
+ afresh each time, both in `other.task.toml`. The wrapper extends
14
+ `cgxx:act`, which runs `mise run --no-cache act-cached`:
14
15
 
15
16
  ```toml
16
17
  [act]
17
- description = "Run CI locally"
18
- run = "mise run --no-cache act-cached"
18
+ extends = "cgxx:act"
19
19
 
20
20
  [act-cached]
21
21
  description = "[Internal] Run CI locally"
@@ -1,23 +0,0 @@
1
- <!--
2
- -
3
- - ~chewygumxx/agentic-library.git
4
- - ::: :/skills/configuring-mise-tasks/references/staged-runs.md
5
- -
6
- -->
7
-
8
- # Staged runs
9
-
10
- Why a staged run watches git's index as the skill's snippet does.
11
-
12
- - **The index is a source.** mise compares a run against the last one
13
- with the same arguments. A second staged run would otherwise skip
14
- a file staged since the first but last edited before it. The index
15
- changes whenever anything is staged, so the run sees it.
16
- - **By an absolute path.** mise runs the template from `.config/mise/`,
17
- where the relative path git prints points outside the repository, and
18
- mise drops a source outside it without a word.
19
- - **Inside the task, for a staged run alone.** Asking git fails outside
20
- a repository, so the template asks only when the run is staged, and an
21
- `--all` run does not rerun on every `git add`.
22
-
23
- <!-- vim:set expandtab shiftwidth=2 filetype=markdown foldlevel=3: -->
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env sh
2
- # vim:set expandtab shiftwidth=4 filetype=sh:
3
- # SPDX-License-Identifier: GPL-3.0-only
4
-
5
- #
6
- #
7
- # ~chewygumxx/agentic-library.git
8
- # ::: :/skills/configuring-mise-tasks/scripts/with-files.sh
9
- #
10
- #
11
-
12
- # Usage: with-files.sh [--staged] [<pathspec>...] -- <command> [<arg>...]
13
- #
14
- # Runs the command with the tracked files matching the pathspecs appended,
15
- # or with --staged, the staged files added, copied, modified or renamed.
16
- # A mise task's --staged flag, exported as $usage_staged=true, does the same.
17
- # No pathspec means every file. Runs nothing when no file matches. Each
18
- # path starts ./, so no tool reads a file named -x as an option.
19
-
20
- set -eu
21
-
22
- usage() {
23
- echo 'usage: with-files.sh [--staged] [<pathspec>...] -- <command> [<arg>...]' >&2
24
- exit 2
25
- }
26
-
27
- staged=
28
- if [ "${usage_staged-}" = true ]; then
29
- staged=1
30
- fi
31
- if [ "${1-}" = --staged ]; then
32
- staged=1
33
- shift
34
- fi
35
-
36
- # Lists the files matching the arguments before --, NUL-separated.
37
- list() {
38
- count=$#
39
- keep=1
40
- while [ "$count" -gt 0 ]; do
41
- arg=$1
42
- shift
43
- count=$((count - 1))
44
- [ "$arg" = -- ] && keep=
45
- [ -n "$keep" ] && set -- "$@" "$arg"
46
- done
47
- if [ -n "$staged" ]; then
48
- git diff -z --cached --name-only --diff-filter=ACMR \
49
- --line-prefix=./ -- "$@"
50
- else
51
- git ls-files -z --format='./%(path)' -- "$@"
52
- fi
53
- }
54
-
55
- for arg; do
56
- [ "$arg" = -- ] && break
57
- done
58
- [ "${arg-}" = -- ] || usage
59
-
60
- files=$(mktemp)
61
- trap 'rm -f "$files"' EXIT
62
- list "$@" >"$files"
63
-
64
- while [ "$1" != -- ]; do
65
- shift
66
- done
67
- shift
68
- [ $# -gt 0 ] || usage
69
-
70
- [ -s "$files" ] || exit 0
71
- xargs -0 "$@" <"$files"