| 1 |
# Templates |
| 2 |
|
| 3 |
Jujutsu supports a functional language to customize output of commands. |
| 4 |
The language consists of literals, keywords, operators, functions, and |
| 5 |
methods. |
| 6 |
|
| 7 |
A couple of `jj` commands accept a template via `-T`/`--template` option. |
| 8 |
|
| 9 |
## Keywords |
| 10 |
|
| 11 |
Keywords represent objects of different types; the types are described in |
| 12 |
a follow-up section. In addition to context-specific keywords, the top-level |
| 13 |
object can be referenced as `self`. |
| 14 |
|
| 15 |
### Commit keywords |
| 16 |
|
| 17 |
In `jj log` templates, all 0-argument methods of [the `Commit` |
| 18 |
type](#commit-type) are available as keywords. For example, `commit_id` is |
| 19 |
equivalent to `self.commit_id()`. |
| 20 |
|
| 21 |
### Operation keywords |
| 22 |
|
| 23 |
In `jj op log` templates, all 0-argument methods of [the `Operation` |
| 24 |
type](#operation-type) are available as keywords. For example, |
| 25 |
`current_operation` is equivalent to `self.current_operation()`. |
| 26 |
|
| 27 |
## Operators |
| 28 |
|
| 29 |
The following operators are supported. `x` and `y` below can be any expression. |
| 30 |
|
| 31 |
Operators are listed in order of binding power from strongest to weakest, e.g. |
| 32 |
`x ++ y * z` is interpreted as `x ++ (y * z)` since `*` has stronger binding |
| 33 |
power than `++`. Infix operators of the same binding power are parsed from left |
| 34 |
to right, e.g. `x * y / z` is interpreted as `(x * y) / z`. |
| 35 |
|
| 36 |
As seen above, parentheses can be used to control evaluation order, e.g. `(x + |
| 37 |
y) * z`. |
| 38 |
|
| 39 |
1. * `x.f()`: Method call. |
| 40 |
* `f(x)`: Function call. |
| 41 |
|
| 42 |
2. * `-x`: Negate integer value. |
| 43 |
* `!x`: Logical not. |
| 44 |
|
| 45 |
3. * `p:x`: String pattern or pattern alias named `p`. |
| 46 |
|
| 47 |
4. * `x * y`, `x / y`, `x % y`: Multiplication / division / remainder. Operands must |
| 48 |
be `Integer`s. |
| 49 |
|
| 50 |
5. * `x + y`, `x - y`: Addition / subtraction. Operands must be `Integer`s. |
| 51 |
|
| 52 |
6. * `x >= y`, `x > y`, `x <= y`, `x < y`: Greater than or equal / greater than / |
| 53 |
lesser than or equal / lesser than. Operands must be `Integer`s. |
| 54 |
|
| 55 |
7. * `x == y`, `x != y`: Equal / not equal. Operands must be either `Boolean`, |
| 56 |
`ByteString`, `Integer`, or `String`. |
| 57 |
|
| 58 |
8. * `x && y`: Logical and, short-circuiting. |
| 59 |
|
| 60 |
9. * `x || y`: Logical or, short-circuiting. |
| 61 |
|
| 62 |
10. * `x ++ y`: Concatenate `x` and `y` templates. |
| 63 |
|
| 64 |
## Global functions |
| 65 |
|
| 66 |
The following functions are defined. |
| 67 |
|
| 68 |
* `fill(width: Integer, content: Template) -> Template`: Fill lines at |
| 69 |
the given `width`. |
| 70 |
* `indent(prefix: Template, content: Template) -> Template`: Indent |
| 71 |
non-empty lines by the given `prefix`. |
| 72 |
* `pad_start(width: Integer, content: Template, [fill_char: Template])`: Pad (or |
| 73 |
right-justify) content by adding leading fill characters. The `content` |
| 74 |
shouldn't have newline character. |
| 75 |
* `pad_end(width: Integer, content: Template, [fill_char: Template])`: Pad (or |
| 76 |
left-justify) content by adding trailing fill characters. The `content` |
| 77 |
shouldn't have newline character. |
| 78 |
* `pad_centered(width: Integer, content: Template, [fill_char: Template])`: Pad |
| 79 |
content by adding both leading and trailing fill characters. If an odd number |
| 80 |
of fill characters are needed, the trailing fill will be one longer than the |
| 81 |
leading fill. The `content` shouldn't have newline characters. |
| 82 |
* `truncate_start(width: Integer, content: Template, [ellipsis: Template])`: |
| 83 |
Truncate `content` by removing leading characters. The `content` shouldn't |
| 84 |
have newline character. If `ellipsis` is provided and `content` was truncated, |
| 85 |
prepend the `ellipsis` to the result. |
| 86 |
* `truncate_end(width: Integer, content: Template, [ellipsis: Template])`: |
| 87 |
Truncate `content` by removing trailing characters. The `content` shouldn't |
| 88 |
have newline character. If `ellipsis` is provided and `content` was truncated, |
| 89 |
append the `ellipsis` to the result. |
| 90 |
* `hash(content: Stringify) -> String`: |
| 91 |
Hash the input and return a hexadecimal string representation of the digest. |
| 92 |
* `label(label: Stringify, content: Template) -> Template`: Apply a custom |
| 93 |
[color label](#color-labels) to the content. The `label` is evaluated as a |
| 94 |
space-separated string. |
| 95 |
* `hyperlink(url: Stringify, text: Template, [fallback: Template]) -> Template`: |
| 96 |
Render `text` as a hyperlink to `url` using [OSC 8 escape sequences](https://github.com/Alhadis/OSC8-Adoption) |
| 97 |
when outputting with color enabled. Otherwise, renders `fallback` instead, |
| 98 |
which defaults to `text`. Use `--color=always` to force hyperlinks when piping |
| 99 |
output to a terminal emulator that supports OSC 8. |
| 100 |
* `raw_escape_sequence(content: Template) -> Template`: Preserves any escape |
| 101 |
sequences in `content` (i.e., bypasses sanitization) and strips labels. |
| 102 |
Note: This function is intended for escape sequences and as such, its output |
| 103 |
is expected to be invisible / of no display width. Outputting content with |
| 104 |
nonzero display width may break wrapping, indentation etc. |
| 105 |
* `replace(pattern: StringPattern, content: Template, replacement: |RegexCaptures| -> Template) -> Template`: |
| 106 |
Replace every match of `pattern` in `content` by formatting the `replacement` |
| 107 |
lambda for each match. |
| 108 |
|
| 109 |
This is similar to [`String.replace()`](#string-type), but operates on |
| 110 |
`Template` content and preserves formatting of the parts of `content` that are |
| 111 |
not replaced. The replacement itself is newly formatted template content. |
| 112 |
|
| 113 |
The lambda argument is a [`RegexCaptures`](#regexcaptures-type) value for the |
| 114 |
current match. Use `.get(index)` to access capture groups by index, `.name(name)` |
| 115 |
to access named capture groups, and `.len()` to get the number of captures |
| 116 |
including capture group 0 for the full match. |
| 117 |
* `stringify(content: Stringify) -> String`: Format `content` to string. This |
| 118 |
effectively removes color labels. |
| 119 |
* `json(value: Serialize) -> String`: Serialize `value` in JSON format. |
| 120 |
* `if(condition: Boolean, then: Any, [else: Any]) -> Any`: |
| 121 |
Conditionally evaluates to `then` / `else` content. |
| 122 |
* `try(expr: Any, fallback: Any...) -> Any`: Evaluates each expression in order |
| 123 |
and returns the first successful result. Suppresses preceding runtime errors, |
| 124 |
but lets parsing errors (such as type errors) pass through. |
| 125 |
* `coalesce(content: Template...) -> Template`: Returns the first **non-empty** |
| 126 |
content. |
| 127 |
* `concat(content: Template...) -> Template`: |
| 128 |
Same as `content_1 ++ ... ++ content_n`. |
| 129 |
* `join(separator: Template, content: Template...) -> Template`: Insert |
| 130 |
`separator` between `content`s. |
| 131 |
* `separate(separator: Template, content: Template...) -> Template`: Insert |
| 132 |
`separator` between **non-empty** `content`s. |
| 133 |
* `surround(prefix: Template, suffix: Template, content: Template) -> Template`: |
| 134 |
Surround **non-empty** content with texts such as parentheses. |
| 135 |
* `config(name: Stringify) -> Option<ConfigValue>`: Look up configuration |
| 136 |
value by `name`. |
| 137 |
* `git_web_url([remote: String]) -> String`: Best-effort conversion of a git |
| 138 |
remote URL to an HTTPS web URL. Defaults to the "origin" remote. Returns an |
| 139 |
empty string on failure. SSH host alias resolution is currently unsupported. |
| 140 |
|
| 141 |
## Types |
| 142 |
|
| 143 |
### `AnnotationLine` type |
| 144 |
|
| 145 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: no_ |
| 146 |
|
| 147 |
The following methods are defined. |
| 148 |
|
| 149 |
* `.commit() -> Commit`: Commit responsible for changing the relevant line. |
| 150 |
* `.content() -> ByteString`: Line content including newline character. |
| 151 |
* `.line_number() -> Integer`: 1-based line number. |
| 152 |
* `.original_line_number() -> Integer`: 1-based line number in the original commit. |
| 153 |
* `.first_line_in_hunk() -> Boolean`: False when the directly preceding line |
| 154 |
references the same commit. |
| 155 |
|
| 156 |
### `Any` type |
| 157 |
|
| 158 |
_Conversion: `Boolean`: no, `Serialize`: maybe, `Template`: maybe_ |
| 159 |
|
| 160 |
All types can be implicitly converted to `Any`. No methods are defined. |
| 161 |
|
| 162 |
### `AnyList` type |
| 163 |
|
| 164 |
_Conversion: `Boolean`: no, `Serialize`: maybe, `Template`: maybe_ |
| 165 |
|
| 166 |
The following methods are defined. |
| 167 |
|
| 168 |
* `.join(separator: Template) -> Template`: Concatenate elements with |
| 169 |
the given `separator`. |
| 170 |
|
| 171 |
### `Boolean` type |
| 172 |
|
| 173 |
_Conversion: `Boolean`: yes, `Serialize`: yes, `Template`: yes_ |
| 174 |
|
| 175 |
No methods are defined. Can be constructed with `false` or `true` literal. |
| 176 |
|
| 177 |
### `ByteString` type |
| 178 |
|
| 179 |
_Conversion: `Boolean`: yes, `Serialize`: yes, `Template`: yes_ |
| 180 |
|
| 181 |
A byte string, whose encoding is considered ASCII-compatible (e.g. UTF-8), but |
| 182 |
isn't guaranteed. This can be implicitly converted to `Boolean`. The following |
| 183 |
methods are defined. |
| 184 |
|
| 185 |
* `.len() -> Integer`: Length in bytes. |
| 186 |
* `.contains(needle: ByteStringify) -> Boolean`: Whether the string contains the |
| 187 |
provided stringifiable value as a substring. |
| 188 |
* `.match(needle: StringPattern) -> ByteString`: Extract the first matching part |
| 189 |
of the string for the given pattern. |
| 190 |
|
| 191 |
An empty string is returned if there is no match. |
| 192 |
* `.starts_with(needle: ByteStringify) -> Boolean`: Whether `needle` is a |
| 193 |
prefix of the string. |
| 194 |
* `.ends_with(needle: ByteStringify) -> Boolean`: Whether `needle` is a suffix |
| 195 |
of the string. |
| 196 |
* `.remove_prefix(needle: ByteStringify) -> ByteString`: Remove the passed |
| 197 |
prefix, if present. |
| 198 |
* `.remove_suffix(needle: ByteStringify) -> ByteString`: Remove the passed |
| 199 |
suffix, if present. |
| 200 |
* `.trim() -> ByteString`: Remove leading and trailing ASCII whitespace. |
| 201 |
* `.trim_start() -> ByteString`: Remove leading ASCII whitespace. |
| 202 |
* `.trim_end() -> ByteString`: Remove trailing ASCII whitespace. |
| 203 |
* `.substr(start: Integer, [end: Integer]) -> ByteString`: Extract substring. |
| 204 |
Indices are 0-based and `end` is exclusive. Negative values count from the end |
| 205 |
of the string, with `-1` being the last byte. If `end` is not given, returns |
| 206 |
from `start` to the end of the string. |
| 207 |
* `.first_line() -> ByteString` |
| 208 |
* `.lines() -> List<ByteString>`: Split into lines excluding newline characters. |
| 209 |
* `.split(separator: StringPattern, [limit: Integer]) -> List<ByteString>`: |
| 210 |
Split into substrings by the given `separator` pattern. If `limit` is |
| 211 |
specified, it determines the maximum number of elements in the result, with |
| 212 |
the remainder of the string returned as the final element. A `limit` of 0 |
| 213 |
returns an empty list. |
| 214 |
* `.replace(pattern: StringPattern, replacement: ByteStringify, [limit: |
| 215 |
Integer]) -> ByteString`: Replace occurrences of the given `pattern` with the |
| 216 |
`replacement` string. |
| 217 |
|
| 218 |
By default, all occurrences are replaced. If `limit` is specified, at most |
| 219 |
that many occurrences are replaced. |
| 220 |
|
| 221 |
Supports capture groups in patterns using `$0` (entire match), `$1`, `$2` etc. |
| 222 |
* `.upper() -> ByteString`: Map each ASCII character to upper case. |
| 223 |
* `.lower() -> ByteString`: Map each ASCII character to lower case. |
| 224 |
|
| 225 |
### `ByteStringify` type |
| 226 |
|
| 227 |
An expression that can be converted to a `ByteString`. |
| 228 |
|
| 229 |
A `String` can be converted to a `ByteString` losslessly. Any types that can be |
| 230 |
converted to `Template` can also be `ByteStringify`. Unlike `Template`, color |
| 231 |
labels are stripped. |
| 232 |
|
| 233 |
### `ChangeId` type |
| 234 |
|
| 235 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 236 |
|
| 237 |
The following methods are defined. |
| 238 |
|
| 239 |
* `.normal_hex() -> String`: Normal hex representation (0-9a-f) instead of the |
| 240 |
canonical "reversed" (z-k) representation. |
| 241 |
* `.short([len: Integer]) -> String` |
| 242 |
* `.shortest([min_len: Integer]) -> ShortestIdPrefix`: Shortest unique prefix. |
| 243 |
|
| 244 |
### `Commit` type |
| 245 |
|
| 246 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: no_ |
| 247 |
|
| 248 |
This type cannot be printed. The following methods are defined. |
| 249 |
|
| 250 |
* `.description() -> String`: Usually ends with a trailing `\n`, if non-blank. |
| 251 |
* `.trailers() -> List<Trailer>`: The trailers at the end of the commit |
| 252 |
description that are formatted as `<key>: <value>`. These are returned in the |
| 253 |
same order as they appear in the description, and there may be multiple |
| 254 |
`Trailer`s with the same key. |
| 255 |
* `.change_id() -> ChangeId` |
| 256 |
* `.commit_id() -> CommitId` |
| 257 |
* `.parents() -> List<Commit>` |
| 258 |
* `.author() -> Signature` |
| 259 |
* `.committer() -> Signature` |
| 260 |
* `.signature() -> Option<CryptographicSignature>`: Cryptographic signature if |
| 261 |
the commit was signed. |
| 262 |
* `.mine() -> Boolean`: Commits where the author's email matches the email of |
| 263 |
the current user. |
| 264 |
* `.working_copies() -> List<WorkspaceRef>`: For multi-workspace repositories, |
| 265 |
returns a list of workspace references for each workspace whose working-copy |
| 266 |
commit matches the current commit. |
| 267 |
* `.current_working_copy() -> Boolean`: True for the working-copy commit of the |
| 268 |
current workspace. |
| 269 |
* `.bookmarks() -> List<CommitRef>`: Local and remote bookmarks pointing to the |
| 270 |
commit. A tracked remote bookmark will be included only if its target is |
| 271 |
different from the local one. |
| 272 |
* `.local_bookmarks() -> List<CommitRef>`: All local bookmarks pointing to the |
| 273 |
commit. |
| 274 |
* `.remote_bookmarks() -> List<CommitRef>`: All remote bookmarks pointing to the |
| 275 |
commit. |
| 276 |
* `.tags() -> List<CommitRef>`: Local and remote tags pointing to the commit. A |
| 277 |
tracked remote tag will be included only if its target is different from the |
| 278 |
local one. |
| 279 |
* `.local_tags() -> List<CommitRef>`: All local tags pointing to the commit. |
| 280 |
* `.remote_tags() -> List<CommitRef>`: All remote tags pointing to the commit. |
| 281 |
* `.divergent() -> Boolean`: True if the commit's change ID corresponds to multiple |
| 282 |
visible commits. |
| 283 |
* `.hidden() -> Boolean`: True if the commit is not visible (a.k.a. abandoned). |
| 284 |
* `.change_offset() -> Option<Integer>`: The [change offset](glossary.md#change-offset) |
| 285 |
of this commit. May not be available for some commits. |
| 286 |
* `.immutable() -> Boolean`: True if the commit is included in [the set of |
| 287 |
immutable commits](config.md#set-of-immutable-commits). |
| 288 |
* `.contained_in(revset: StringLiteral) -> Boolean`: True if the commit is included in |
| 289 |
[the provided revset](revsets.md). |
| 290 |
* `.conflict() -> Boolean`: True if the commit contains merge conflicts. |
| 291 |
* `.empty() -> Boolean`: True if the commit modifies no files. |
| 292 |
* `.diff([files: StringLiteral]) -> TreeDiff`: Changes from the parents within [the |
| 293 |
`files` expression](filesets.md). All files are compared by default, but it is |
| 294 |
likely to change in future version to respect the command line path arguments. |
| 295 |
* `.files([files: StringLiteral]) -> List<TreeEntry>`: Files that exist in this commit, |
| 296 |
matching [the `files` expression](filesets.md). Use `.diff().files()` to list |
| 297 |
changed files. |
| 298 |
* `.conflicted_files() -> List<TreeEntry>`: Conflicted files in this commit. |
| 299 |
* `.root() -> Boolean`: True if the commit is the root commit. |
| 300 |
|
| 301 |
### `CommitEvolutionEntry` type |
| 302 |
|
| 303 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: no_ |
| 304 |
|
| 305 |
This type cannot be printed. The following methods are defined. |
| 306 |
|
| 307 |
* `.commit() -> Commit`: New commit. |
| 308 |
* `.operation() -> Operation`: Operation where the commit was created or |
| 309 |
rewritten. |
| 310 |
* `.predecessors() -> List<Commit>`: Predecessor commits of this entry. |
| 311 |
* `.inter_diff([files: StringLiteral]) -> TreeDiff`: Changes between this commit and its |
| 312 |
predecessor version(s), rebased onto the parents of this commit to avoid unrelated |
| 313 |
changes (similar to `jj evolog -p`). |
| 314 |
|
| 315 |
### `CommitId` type |
| 316 |
|
| 317 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 318 |
|
| 319 |
The following methods are defined. |
| 320 |
|
| 321 |
* `.short([len: Integer]) -> String` |
| 322 |
* `.shortest([min_len: Integer]) -> ShortestIdPrefix`: Shortest unique prefix. |
| 323 |
|
| 324 |
### `CommitRef` type |
| 325 |
|
| 326 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 327 |
|
| 328 |
The following methods are defined. |
| 329 |
|
| 330 |
* `.name() -> RefSymbol`: Local bookmark or tag name. |
| 331 |
* `.remote() -> Option<RefSymbol>`: Remote name if this is a remote ref. |
| 332 |
* `.present() -> Boolean`: True if the ref points to any commit. |
| 333 |
* `.conflict() -> Boolean`: True if [the bookmark or tag is |
| 334 |
conflicted](bookmarks.md#conflicts). |
| 335 |
* `.normal_target() -> Option<Commit>`: Target commit if the ref is not |
| 336 |
conflicted and points to a commit. |
| 337 |
* `.removed_targets() -> List<Commit>`: Old target commits if conflicted. |
| 338 |
* `.added_targets() -> List<Commit>`: New target commits. The list usually |
| 339 |
contains one "normal" target. |
| 340 |
* `.tracked() -> Boolean`: True if the ref is tracked by a local ref. The local |
| 341 |
ref might have been deleted (but not pushed yet.) |
| 342 |
* `.tracking_present() -> Boolean`: True if the ref is tracked by a local ref, |
| 343 |
and if the local ref points to any commit. |
| 344 |
* `.tracking_ahead_count() -> SizeHint`: Number of commits ahead of the tracking |
| 345 |
local ref. |
| 346 |
* `.tracking_behind_count() -> SizeHint`: Number of commits behind of the |
| 347 |
tracking local ref. |
| 348 |
* `.synced() -> Boolean`: For a local bookmark, true if synced with all tracked |
| 349 |
remotes. For a remote bookmark, true if synced with the tracking local |
| 350 |
bookmark. |
| 351 |
|
| 352 |
### `ConfigValue` type |
| 353 |
|
| 354 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 355 |
|
| 356 |
This type can be printed in TOML syntax. The following methods are defined. |
| 357 |
|
| 358 |
* `.as_boolean() -> Boolean`: Extract boolean. |
| 359 |
* `.as_integer() -> Integer`: Extract integer. |
| 360 |
* `.as_string() -> String`: Extract string. This does not convert non-string |
| 361 |
value (e.g. integer) to string. |
| 362 |
* `.as_string_list() -> List<String>`: Extract list of strings. |
| 363 |
|
| 364 |
### `CryptographicSignature` type |
| 365 |
|
| 366 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: no_ |
| 367 |
|
| 368 |
The following methods are defined. |
| 369 |
|
| 370 |
* `.status() -> String`: The signature's status (`"good"`, `"bad"`, `"unknown"`, |
| 371 |
`"invalid"`). |
| 372 |
* `.key() -> String`: The signature's key id representation (for GPG and SSH, |
| 373 |
this is the public key fingerprint). |
| 374 |
* `.display() -> String`: The signature's display string (for GPG, this is the |
| 375 |
formatted primary user ID; for SSH, this is the principal). |
| 376 |
|
| 377 |
!!! warning |
| 378 |
|
| 379 |
Calling any of `.status()`, `.key()`, or `.display()` is slow, as it incurs |
| 380 |
the performance cost of verifying the signature (for example shelling out |
| 381 |
to `gpg` or `ssh-keygen`). Though consecutive calls will be faster, because |
| 382 |
the backend caches the verification result. |
| 383 |
|
| 384 |
!!! info |
| 385 |
|
| 386 |
As opposed to calling any of `.status()`, `.key()`, or `.display()`, |
| 387 |
checking for signature presence through boolean coercion is fast: |
| 388 |
``` |
| 389 |
if(commit.signature(), "commit has a signature", "commit is unsigned") |
| 390 |
``` |
| 391 |
|
| 392 |
### `DiffStatEntry` type |
| 393 |
|
| 394 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: no_ |
| 395 |
|
| 396 |
This type holds the diff stats per file. The following methods are defined. |
| 397 |
|
| 398 |
* `.bytes_delta() -> Integer`: The difference in size of the file, in bytes. |
| 399 |
* `.lines_added() -> Integer`: Number of lines added. |
| 400 |
* `.lines_removed() -> Integer`: Number of lines deleted. |
| 401 |
* `.path() -> RepoPath`: Path to the entry. If the entry is a copy / rename, this |
| 402 |
points to the target (or right) entry. |
| 403 |
* `.display_diff_path() -> String`: Format path for display, taking into account copy / rename information. |
| 404 |
* `.status() -> String`: One of `"modified"`, `"added"`, `"removed"`, `"copied"`, or `"renamed"`. |
| 405 |
* `.status_char() -> String`: One of `"M"` (modified), `"A"` (added), `"D"` (removed), |
| 406 |
`"C"` (copied), or `"R"` (renamed). |
| 407 |
|
| 408 |
### `DiffStats` type |
| 409 |
|
| 410 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: yes_ |
| 411 |
|
| 412 |
This type can be printed as a histogram of the changes. The following methods |
| 413 |
are defined. |
| 414 |
|
| 415 |
* `.files() -> List<DiffStatEntry>`: Per-file stats for changed files. |
| 416 |
* `.total_added() -> Integer`: Total number of insertions. |
| 417 |
* `.total_removed() -> Integer`: Total number of deletions. |
| 418 |
|
| 419 |
### `Email` type |
| 420 |
|
| 421 |
_Conversion: `Boolean`: yes, `Serialize`: yes, `Template`: yes_ |
| 422 |
|
| 423 |
The email field of a signature may or may not look like an email address. It may |
| 424 |
be empty, may not contain the symbol `@`, and could in principle contain |
| 425 |
multiple `@`s. |
| 426 |
|
| 427 |
The following methods are defined. |
| 428 |
|
| 429 |
* `.local() -> String`: the part of the email before the first `@`, usually the |
| 430 |
username. |
| 431 |
* `.domain() -> String`: the part of the email after the first `@` or the empty |
| 432 |
string. |
| 433 |
|
| 434 |
### `FsPath` type |
| 435 |
|
| 436 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 437 |
|
| 438 |
A filesystem path. Paths can contain bytes that are not valid UTF-8. Rendering |
| 439 |
and path formatting methods preserve those bytes. Serialization with `json()` |
| 440 |
follows Rust's `Path` serialization, which can reject non-UTF-8 paths. |
| 441 |
|
| 442 |
The following methods are defined. |
| 443 |
|
| 444 |
* `.absolute() -> FsPath`: Return an absolute filesystem path. |
| 445 |
* `.relative() -> FsPath`: Return the path relative to the current working |
| 446 |
directory. |
| 447 |
|
| 448 |
### `Integer` type |
| 449 |
|
| 450 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 451 |
|
| 452 |
No methods are defined. |
| 453 |
|
| 454 |
### `List` type |
| 455 |
|
| 456 |
_Conversion: `Boolean`: yes, `Serialize`: maybe, `Template`: maybe_ |
| 457 |
|
| 458 |
A list can be implicitly converted to `Boolean`. The following methods are |
| 459 |
defined. |
| 460 |
|
| 461 |
* `.len() -> Integer`: Number of elements in the list. |
| 462 |
* `.join(separator: Template) -> Template`: Concatenate elements with |
| 463 |
the given `separator`. |
| 464 |
* `.filter(|item| expression) -> List`: Filter list elements by predicate |
| 465 |
`expression`. Example: `description.lines().filter(|s| s.contains("#"))` |
| 466 |
* `.map(|item| expression) -> AnyList`: Apply template `expression` |
| 467 |
to each element. Example: `parents.map(|c| c.commit_id().short())` |
| 468 |
* `.any(|item| expression) -> Boolean`: Returns true if any element satisfies |
| 469 |
the predicate `expression`. Example: `parents.any(|c| c.description().contains("fix"))` |
| 470 |
* `.all(|item| expression) -> Boolean`: Returns true if all elements satisfy |
| 471 |
the predicate `expression`. Example: `parents.all(|c| c.mine())` |
| 472 |
* `.first() -> T`: Returns the first element. Errors if the list is empty. |
| 473 |
* `.last() -> T`: Returns the last element. Errors if the list is empty. |
| 474 |
* `.get(index: Integer) -> T`: Returns the element at `index` (0-based). Errors |
| 475 |
if the index is out of bounds. |
| 476 |
* `.reverse() -> List`: Returns the list in reverse order. |
| 477 |
* `.skip(count: Integer) -> List`: Skips the first `count` elements and |
| 478 |
returns the rest. |
| 479 |
* `.take(count: Integer) -> List`: Returns only the first `count` elements. |
| 480 |
|
| 481 |
### `List<Trailer>` type |
| 482 |
|
| 483 |
The following methods are defined. See also the `List` type. |
| 484 |
|
| 485 |
* `.contains_key(key: Stringify) -> Boolean`: True if the commit description |
| 486 |
contains at least one trailer with the key `key`. |
| 487 |
|
| 488 |
### `Operation` type |
| 489 |
|
| 490 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: no_ |
| 491 |
|
| 492 |
This type cannot be printed. The following methods are defined. |
| 493 |
|
| 494 |
* `.current_operation() -> Boolean` |
| 495 |
* `.description() -> String` |
| 496 |
* `.id() -> OperationId` |
| 497 |
* `.attributes() -> String` |
| 498 |
* `.time() -> TimestampRange` |
| 499 |
* `.user() -> String` |
| 500 |
* `.snapshot() -> Boolean`: True if the operation is a snapshot operation. |
| 501 |
* `.workspace_name() -> String`: The name of the workspace the operation was |
| 502 |
created from. An empty string if the operation wasn't created from a |
| 503 |
workspace. |
| 504 |
* `.root() -> Boolean`: True if the operation is the root operation. |
| 505 |
* `.parents() -> List<Operation>` |
| 506 |
|
| 507 |
### `OperationId` type |
| 508 |
|
| 509 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 510 |
|
| 511 |
The following methods are defined. |
| 512 |
|
| 513 |
* `.short([len: Integer]) -> String` |
| 514 |
|
| 515 |
### `Option` type |
| 516 |
|
| 517 |
_Conversion: `Boolean`: yes, `Serialize`: maybe, `Template`: maybe_ |
| 518 |
|
| 519 |
An option can be implicitly converted to `Boolean` denoting whether the |
| 520 |
contained value is set. If set, all methods of the contained value can be |
| 521 |
invoked. If not set, an error will be reported inline on method call. |
| 522 |
|
| 523 |
On comparison between two optional values or optional and non-optional values, |
| 524 |
unset value is not an error. Unset value is considered less than any set values. |
| 525 |
|
| 526 |
### `RefSymbol` type |
| 527 |
|
| 528 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 529 |
|
| 530 |
[A `String` type](#string-type), but is formatted as revset symbol by quoting |
| 531 |
and escaping if necessary. Unlike strings, this cannot be implicitly converted |
| 532 |
to `Boolean`. |
| 533 |
|
| 534 |
### `RegexCaptures` type |
| 535 |
|
| 536 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: no_ |
| 537 |
|
| 538 |
This type is passed to the replacement lambda of the global |
| 539 |
[`replace()`](#global-functions) function. |
| 540 |
|
| 541 |
The following methods are defined. |
| 542 |
|
| 543 |
* `.len() -> Integer`: Number of capture groups, including capture group 0 for |
| 544 |
the full match. |
| 545 |
* `.get(index: Integer) -> ByteString`: Returns the capture group at `index`. |
| 546 |
Capture group 0 is the full match. Errors if the index is out of bounds. |
| 547 |
* `.name(name: Stringify) -> ByteString`: Returns the named capture group |
| 548 |
`name`. Errors if there is no such named capture group. |
| 549 |
|
| 550 |
### `RepoPath` type |
| 551 |
|
| 552 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 553 |
|
| 554 |
A slash-separated path relative to the repository root. The following methods |
| 555 |
are defined. |
| 556 |
|
| 557 |
* `.absolute() -> FsPath`: Absolute filesystem path. |
| 558 |
* `.display() -> String`: Format path for display. The formatted path uses |
| 559 |
platform-native separator, and is relative to the current working directory. |
| 560 |
* `.parent() -> Option<RepoPath>`: Parent directory path. |
| 561 |
|
| 562 |
### `Serialize` type |
| 563 |
|
| 564 |
An expression that can be serialized in machine-readable format such as JSON. |
| 565 |
|
| 566 |
!!! note |
| 567 |
|
| 568 |
Field names and value types in the serialized output are usually stable |
| 569 |
across jj versions, but the backward compatibility isn't guaranteed. If the |
| 570 |
underlying data model is updated, the serialized output may change. |
| 571 |
|
| 572 |
### `ShortestIdPrefix` type |
| 573 |
|
| 574 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 575 |
|
| 576 |
The following methods are defined. |
| 577 |
|
| 578 |
* `.prefix() -> String` |
| 579 |
* `.rest() -> String` |
| 580 |
* `.upper() -> ShortestIdPrefix` |
| 581 |
* `.lower() -> ShortestIdPrefix` |
| 582 |
|
| 583 |
### `Signature` type |
| 584 |
|
| 585 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 586 |
|
| 587 |
The following methods are defined. |
| 588 |
|
| 589 |
* `.name() -> String` |
| 590 |
* `.email() -> Email` |
| 591 |
* `.timestamp() -> Timestamp` |
| 592 |
|
| 593 |
### `SizeHint` type |
| 594 |
|
| 595 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: no_ |
| 596 |
|
| 597 |
This type cannot be printed. The following methods are defined. |
| 598 |
|
| 599 |
* `.lower() -> Integer`: Lower bound. |
| 600 |
* `.upper() -> Option<Integer>`: Upper bound if known. |
| 601 |
* `.exact() -> Option<Integer>`: Exact value if upper bound is known and it |
| 602 |
equals to the lower bound. |
| 603 |
* `.zero() -> Boolean`: True if upper bound is known and is `0`. Equivalent to |
| 604 |
`.upper() == 0`. |
| 605 |
|
| 606 |
### `String` type |
| 607 |
|
| 608 |
_Conversion: `Boolean`: yes, `Serialize`: yes, `Template`: yes_ |
| 609 |
|
| 610 |
A UTF-8-encoded string. This can be implicitly converted to `Boolean`. The |
| 611 |
following methods are defined. |
| 612 |
|
| 613 |
* `.len() -> Integer`: Length in UTF-8 bytes. |
| 614 |
* `.contains(needle: Stringify) -> Boolean`: Whether the string contains the |
| 615 |
provided stringifiable value as a substring. |
| 616 |
* `.match(needle: StringPattern) -> String`: Extracts |
| 617 |
the first matching part of the string for the given pattern. |
| 618 |
|
| 619 |
An empty string is returned if there is no match. |
| 620 |
* `.starts_with(needle: Stringify) -> Boolean` |
| 621 |
* `.ends_with(needle: Stringify) -> Boolean` |
| 622 |
* `.remove_prefix(needle: Stringify) -> String`: Removes the passed prefix, if |
| 623 |
present. |
| 624 |
* `.remove_suffix(needle: Stringify) -> String`: Removes the passed suffix, if |
| 625 |
present. |
| 626 |
* `.trim() -> String`: Removes leading and trailing whitespace |
| 627 |
* `.trim_start() -> String`: Removes leading whitespace |
| 628 |
* `.trim_end() -> String`: Removes trailing whitespace |
| 629 |
* `.substr(start: Integer, [end: Integer]) -> String`: Extract substring. The |
| 630 |
`start` / `end` indices should be specified in units of UTF-8 bytes. Indices are |
| 631 |
0-based and `end` is exclusive. Negative values count from the end of the |
| 632 |
string, with `-1` being the last byte. If the `start` index is in the middle |
| 633 |
of a UTF-8 codepoint, the codepoint is fully part of the result. If the `end` |
| 634 |
index is in the middle of a UTF-8 codepoint, the codepoint is not part of the |
| 635 |
result. If `end` is not given, returns from `start` to the end of the string. |
| 636 |
* `.first_line() -> String` |
| 637 |
* `.lines() -> List<String>`: Split into lines excluding newline characters. |
| 638 |
* `.split(separator: StringPattern, [limit: Integer]) -> List<String>`: Split |
| 639 |
into substrings by the given `separator` pattern. If `limit` is specified, it |
| 640 |
determines the maximum number of elements in the result, with the remainder of |
| 641 |
the string returned as the final element. A `limit` of 0 returns an empty |
| 642 |
list. |
| 643 |
* `.replace(pattern: StringPattern, replacement: Stringify, [limit: Integer]) -> |
| 644 |
String`: Replace occurrences of the given `pattern` with the `replacement` |
| 645 |
string. |
| 646 |
|
| 647 |
By default, all occurrences are replaced. If `limit` is specified, at most |
| 648 |
that many occurrences are replaced. |
| 649 |
|
| 650 |
Supports capture groups in patterns using `$0` (entire match), `$1`, `$2` etc. |
| 651 |
* `.upper() -> String` |
| 652 |
* `.lower() -> String` |
| 653 |
* `.escape_json() -> String`: Serializes the string in JSON format. This |
| 654 |
function is useful for making machine-readable templates. For example, you |
| 655 |
can use it in a template like `'{ "foo": ' ++ foo.escape_json() ++ ' }'` to |
| 656 |
return a JSON/JSONL. |
| 657 |
|
| 658 |
### `Stringify` type |
| 659 |
|
| 660 |
An expression that can be converted to a `String`. |
| 661 |
|
| 662 |
Any types that can be converted to `Template` can also be `Stringify`. Unlike |
| 663 |
`Template`, color labels are stripped. Invalid UTF-8 sequences are rejected. |
| 664 |
|
| 665 |
### `StringLiteral` type |
| 666 |
|
| 667 |
A string literal known at parse time. Unlike `Stringify`, this cannot be a |
| 668 |
dynamic expression - it must be a literal value like `"main"` or `"format"`. |
| 669 |
|
| 670 |
String literals must be surrounded by single or double quotes (`'` or `"`). |
| 671 |
A double-quoted string literal supports the following escape sequences: |
| 672 |
|
| 673 |
* `\"`: double quote |
| 674 |
* `\\`: backslash |
| 675 |
* `\t`: horizontal tab |
| 676 |
* `\r`: carriage return |
| 677 |
* `\n`: new line |
| 678 |
* `\0`: null |
| 679 |
* `\e`: escape (i.e., `\x1b`) |
| 680 |
* `\xHH`: byte with hex value `HH` |
| 681 |
|
| 682 |
Other escape sequences are not supported. Any UTF-8 characters are allowed |
| 683 |
inside a string literal, with two exceptions: unescaped `"`-s and uses of `\` |
| 684 |
that don't form a valid escape sequence. |
| 685 |
|
| 686 |
A single-quoted string literal has no escape syntax. `'` can't be expressed |
| 687 |
inside a single-quoted string literal. |
| 688 |
|
| 689 |
String literals have their own type so that the value can be validated at parse |
| 690 |
time. For example, `contained_in(revset)` requires a literal so the revset can |
| 691 |
be parsed and checked before the template is evaluated. |
| 692 |
|
| 693 |
### `StringPattern` type |
| 694 |
|
| 695 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: no_ |
| 696 |
|
| 697 |
These are the exact same as the [String pattern type] in revsets, except that |
| 698 |
quotes are mandatory. |
| 699 |
|
| 700 |
Literal strings may be used, which are interpreted as case-sensitive substring |
| 701 |
matching. |
| 702 |
|
| 703 |
Currently `StringPattern` values cannot be passed around as values and may |
| 704 |
only occur directly in the call site they are used in. |
| 705 |
|
| 706 |
[String pattern type]: revsets.md#string-patterns |
| 707 |
|
| 708 |
### `Template` type |
| 709 |
|
| 710 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: yes_ |
| 711 |
|
| 712 |
Most types can be implicitly converted to `Template`. No methods are defined. |
| 713 |
|
| 714 |
### `Timestamp` type |
| 715 |
|
| 716 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 717 |
|
| 718 |
The following methods are defined. |
| 719 |
|
| 720 |
* `.ago() -> String`: Format as relative timestamp. |
| 721 |
* `.format(format: Stringify) -> String`: Format with [the specified strftime-like |
| 722 |
format string](https://docs.rs/chrono/latest/chrono/format/strftime/). |
| 723 |
* `.utc() -> Timestamp`: Convert timestamp into UTC timezone. |
| 724 |
* `.local() -> Timestamp`: Convert timestamp into local timezone. |
| 725 |
* `.after(date: StringLiteral) -> Boolean`: True if the timestamp is exactly at or |
| 726 |
after the given date. Supported date formats are the same as the revset |
| 727 |
[Date pattern type]. |
| 728 |
* `.before(date: StringLiteral) -> Boolean`: True if the timestamp is before, but |
| 729 |
not including, the given date. Supported date formats are the same as the |
| 730 |
revset [Date pattern type]. |
| 731 |
* `.since(start: Timestamp) -> TimestampRange`: The TimestampRange between `start` and |
| 732 |
`self`. It may be used in conjunction with `TimestampRange::duration` to obtain |
| 733 |
a human-friendly duration between two `Timestamp`s. |
| 734 |
|
| 735 |
[Date pattern type]: revsets.md#date-patterns |
| 736 |
|
| 737 |
### `TimestampRange` type |
| 738 |
|
| 739 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 740 |
|
| 741 |
The following methods are defined. |
| 742 |
|
| 743 |
* `.start() -> Timestamp` |
| 744 |
* `.end() -> Timestamp` |
| 745 |
* `.duration() -> String` |
| 746 |
|
| 747 |
### `Trailer` type |
| 748 |
|
| 749 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: yes_ |
| 750 |
|
| 751 |
The following methods are defined. |
| 752 |
|
| 753 |
* `.key() -> String` |
| 754 |
* `.value() -> String` |
| 755 |
|
| 756 |
### `TreeDiff` type |
| 757 |
|
| 758 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: no_ |
| 759 |
|
| 760 |
This type cannot be printed. The following methods are defined. |
| 761 |
|
| 762 |
* `.files() -> List<TreeDiffEntry>`: Changed files. |
| 763 |
* `.color_words([context: Integer]) -> Template`: Format as a word-level diff |
| 764 |
with changes indicated only by color. |
| 765 |
* `.git([context: Integer]) -> Template`: Format as a Git diff. |
| 766 |
* `.stat([width: Integer], [max_bar_width: Integer]) -> DiffStats`: Calculate |
| 767 |
stats of changed lines. `width` sets the entire width of the diff stat |
| 768 |
including paths, and `max_bar_width` limits the maximum character length of |
| 769 |
the `++--` bar. |
| 770 |
* `.summary() -> Template`: Format as a list of status code and path pairs. |
| 771 |
|
| 772 |
### `TreeDiffEntry` type |
| 773 |
|
| 774 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: no_ |
| 775 |
|
| 776 |
This type cannot be printed. The following methods are defined. |
| 777 |
|
| 778 |
* `.path() -> RepoPath`: Path to the entry. If the entry is a copy / rename, this |
| 779 |
points to the target (or right) entry. |
| 780 |
* `.display_diff_path() -> String`: Format path for display, taking into account copy / rename information. |
| 781 |
* `.status() -> String`: One of `"modified"`, `"added"`, `"removed"`, |
| 782 |
`"copied"`, or `"renamed"`. |
| 783 |
* `.status_char() -> String`: Single-character status indicator: `"M"` for modified, |
| 784 |
`"A"` for added, `"D"` for removed, `"C"` for copied, or `"R"` for renamed. |
| 785 |
* `.source() -> TreeEntry`: The source (or left) entry. |
| 786 |
* `.target() -> TreeEntry`: The target (or right) entry. |
| 787 |
|
| 788 |
### `TreeEntry` type |
| 789 |
|
| 790 |
_Conversion: `Boolean`: no, `Serialize`: no, `Template`: no_ |
| 791 |
|
| 792 |
This type cannot be printed. The following methods are defined. |
| 793 |
|
| 794 |
* `.path() -> RepoPath`: Path to the entry. |
| 795 |
* `.conflict() -> Boolean`: True if the entry is a merge conflict. |
| 796 |
* `.conflict_side_count() -> Integer`: Number of sides in the merge conflict (1 if not |
| 797 |
conflicted, 2 or more for multi-way merges). |
| 798 |
* `.file_type() -> String`: One of `"file"`, `"symlink"`, `"tree"`, |
| 799 |
`"git-submodule"`, or `"conflict"`. |
| 800 |
* `.executable() -> Boolean`: True if the entry is an executable file. |
| 801 |
|
| 802 |
### `WorkspaceRef` type |
| 803 |
|
| 804 |
_Conversion: `Boolean`: no, `Serialize`: yes, `Template`: yes_ |
| 805 |
|
| 806 |
The following methods are defined. |
| 807 |
|
| 808 |
* `.name() -> RefSymbol`: Returns the workspace name as a symbol. |
| 809 |
* `.target() -> Commit`: Returns the working-copy commit of this workspace. |
| 810 |
* `.root() -> Option<FsPath>`: Returns the workspace root path, if the root path |
| 811 |
is recorded and can be resolved. |
| 812 |
|
| 813 |
This is optional because workspaces created before jj 0.38.0 did not record |
| 814 |
workspace root paths, and a recorded path can also become stale if the |
| 815 |
workspace directory is moved or deleted. |
| 816 |
|
| 817 |
## Color labels |
| 818 |
|
| 819 |
You can [customize the output colors][config-colors] by using color labels. `jj` |
| 820 |
adds some labels automatically; they can also be added manually. |
| 821 |
|
| 822 |
Template fragments are usually **automatically** labeled with the command name, |
| 823 |
the context (or the top-level object), and the method names. For example, the |
| 824 |
following template is labeled as `op_log operation id short` automatically: |
| 825 |
|
| 826 |
```sh |
| 827 |
jj op log -T 'self.id().short()' |
| 828 |
``` |
| 829 |
|
| 830 |
The exact names of such labels are often straightforward, but are not currently |
| 831 |
documented. You can discover the actual label names used with the |
| 832 |
`--color=debug` option: |
| 833 |
|
| 834 |
```sh |
| 835 |
jj op log -T 'self.id().short()' --color=debug |
| 836 |
``` |
| 837 |
|
| 838 |
This can be useful if you are trying to figure out whether or not a label is |
| 839 |
present or which labels you should define or override colors for to get the |
| 840 |
output that you want. |
| 841 |
|
| 842 |
Additionally, you can **manually** insert arbitrary labels using the |
| 843 |
`label(label, content)` function. For example, |
| 844 |
|
| 845 |
```sh |
| 846 |
jj op log -T '"ID: " ++ self.id().short().substr(0, 1) ++ label("id short", "<redacted>")' |
| 847 |
``` |
| 848 |
|
| 849 |
will print "ID:" in the default style, and the string `<redacted>` in the same |
| 850 |
style as the first character of the id. It would also be fine to use an |
| 851 |
arbitrary template instead of the string `"<redacted>"`, possibly including |
| 852 |
nested invocations of `label()`. |
| 853 |
|
| 854 |
You are free to use custom label names as well. This will only have a visible |
| 855 |
effect if you also [customize their colors][config-colors] explicitly. |
| 856 |
|
| 857 |
To see all the default colors and what customizations apply from your own |
| 858 |
config, run: |
| 859 |
|
| 860 |
```sh |
| 861 |
jj config list --include-defaults --include-overridden colors |
| 862 |
``` |
| 863 |
|
| 864 |
The default colors can be found in [`colors.toml`], and the default explicitly |
| 865 |
added labels (such as `mutable` or `divergent`) can be found in |
| 866 |
[`templates.toml`]. Labels that appear in `colors.toml` but that are not |
| 867 |
explicitly present in `templates.toml` will have been automatically added by |
| 868 |
`jj` (such as `author` or `change_id`). |
| 869 |
|
| 870 |
[config-colors]: config.md#custom-colors-and-styles |
| 871 |
[`colors.toml`]: https://github.com/jj-vcs/jj/blob/main/cli/src/config/colors.toml |
| 872 |
[`templates.toml`]: https://github.com/jj-vcs/jj/blob/main/cli/src/config/templates.toml |
| 873 |
|
| 874 |
## Configuration |
| 875 |
|
| 876 |
The default templates and aliases() are defined in the `[templates]` and |
| 877 |
`[template-aliases]` sections of the config respectively. The exact definitions |
| 878 |
can be seen in the [`templates.toml`] file. |
| 879 |
|
| 880 |
<!--- TODO: Find a way to embed the default config files in the docs --> |
| 881 |
|
| 882 |
New keywords, functions, and `<name>:<value>` patterns can be defined as |
| 883 |
aliases, by using any combination of the predefined keywords/functions and other |
| 884 |
aliases. |
| 885 |
|
| 886 |
Alias functions can be overloaded by the number of parameters. However, builtin |
| 887 |
functions will be shadowed by name, and can't co-exist with aliases. |
| 888 |
|
| 889 |
For example: |
| 890 |
|
| 891 |
```toml |
| 892 |
[template-aliases] |
| 893 |
sh = "commit_id.short()" |
| 894 |
'commit_change_ids' = ''' |
| 895 |
concat( |
| 896 |
format_field("Commit ID", commit_id), |
| 897 |
format_field("Change ID", change_id), |
| 898 |
) |
| 899 |
''' |
| 900 |
'format_field(key, value)' = 'key ++ ": " ++ value ++ "\n"' |
| 901 |
'json:x' = 'json(x) ++ "\n"' |
| 902 |
``` |
| 903 |
|
| 904 |
### Alias descriptions |
| 905 |
|
| 906 |
Alias descriptions can be surfaced in shell completions by defining the alias |
| 907 |
as a table with `.doc` and `.definition` properties. For example: |
| 908 |
|
| 909 |
```toml |
| 910 |
[template-aliases] |
| 911 |
sh = { definition = 'commit_id.short()', doc = 'Short commit ID' } |
| 912 |
``` |
| 913 |
|
| 914 |
You can also use the dotted key syntax: |
| 915 |
|
| 916 |
```toml |
| 917 |
[template-aliases] |
| 918 |
sh.definition = 'commit_id.short()' |
| 919 |
sh.doc = 'Short commit ID' |
| 920 |
``` |
| 921 |
|
| 922 |
## Examples |
| 923 |
|
| 924 |
Get short commit IDs of the working-copy parents: |
| 925 |
|
| 926 |
```sh |
| 927 |
jj log -G -r @ -T 'parents.map(|c| c.commit_id().short()).join(",")' |
| 928 |
``` |
| 929 |
|
| 930 |
Show machine-readable list of full commit and change IDs: |
| 931 |
|
| 932 |
```sh |
| 933 |
jj log -G -T 'commit_id ++ " " ++ change_id ++ "\n"' |
| 934 |
``` |
| 935 |
|
| 936 |
Print the description of the current commit, defaulting to `(no description set)`: |
| 937 |
|
| 938 |
```sh |
| 939 |
jj log -G -r @ -T 'coalesce(description, "(no description set)\n")' |
| 940 |
``` |
| 941 |
|
| 942 |
For each revision, print the name of its first bookmark or change ID: |
| 943 |
|
| 944 |
```sh |
| 945 |
jj log -T 'try(bookmarks.first().name(), change_id.shortest(8)) ++ "\n"' |
| 946 |
``` |