Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jj): add jj module to display repository status #5772

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,26 @@
}
]
},
"jj_status": {
"default": {
"branch_style": "purple",
"change_id_prefix_style": "purple",
"change_id_suffix_style": "bright-black",
"commit_id_prefix_style": "blue",
"commit_id_suffix_style": "bright-black",
"disabled": false,
"divergent_symbol": " 💥",
"format": "\\[$symbol[$change_id_prefix]($change_id_prefix_style)[$change_id_suffix]($change_id_suffix_style) [$commit_id_prefix]($commit_id_prefix_style)[$commit_id_suffix]($commit_id_suffix_style) on [$branch]($branch_style)$no_description_symbol$divergent_symbol\\]",
"no_description_symbol": " 📝",
"symbol": "🍐 ",
"truncation_length": 8
},
"allOf": [
{
"$ref": "#/definitions/JJConfig"
}
]
},
"jobs": {
"default": {
"disabled": false,
Expand Down Expand Up @@ -3939,6 +3959,58 @@
},
"additionalProperties": false
},
"JJConfig": {
"type": "object",
"properties": {
"symbol": {
"default": "🍐 ",
"type": "string"
},
"format": {
"default": "\\[$symbol[$change_id_prefix]($change_id_prefix_style)[$change_id_suffix]($change_id_suffix_style) [$commit_id_prefix]($commit_id_prefix_style)[$commit_id_suffix]($commit_id_suffix_style) on [$branch]($branch_style)$no_description_symbol$divergent_symbol\\]",
"type": "string"
},
"disabled": {
"default": false,
"type": "boolean"
},
"change_id_prefix_style": {
"default": "purple",
"type": "string"
},
"change_id_suffix_style": {
"default": "bright-black",
"type": "string"
},
"commit_id_prefix_style": {
"default": "blue",
"type": "string"
},
"commit_id_suffix_style": {
"default": "bright-black",
"type": "string"
},
"truncation_length": {
"default": 8,
"type": "integer",
"format": "uint8",
"minimum": 0.0
},
"no_description_symbol": {
"default": " 📝",
"type": "string"
},
"divergent_symbol": {
"default": " 💥",
"type": "string"
},
"branch_style": {
"default": "purple",
"type": "string"
}
},
"additionalProperties": false
},
"JobsConfig": {
"type": "object",
"properties": {
Expand Down
73 changes: 73 additions & 0 deletions docs/config/README.md
0xdeafbeef marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ $directory\
$vcsh\
$fossil_branch\
$fossil_metrics\
$jj_status\
$git_branch\
$git_commit\
$git_state\
Expand Down Expand Up @@ -2445,6 +2446,78 @@ number_threshold = 4
symbol_threshold = 0
```

## JJ

The `jj` module reflects the current status of your Jujutsu repository. It shows
different symbols and formats depending on the state of your work in progress,
including changes, commits, branch, and more.

The `jj` module is only shown when you're in a directory that is part of a
Jujutsu repository.

The default functionality includes displaying:

- current change id
- current commit id

::: warning

This module requires the Jujutsu command line tool to be installed and
accessible in your system's PATH for it to function correctly.

:::

### Options

| Option | Default | Description |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `symbol` | `'🍐 '` | The string used before displaying the repository status. |
| `no_description_symbol` | `' 📝'` | Is displayed when change description is empty. |
| `divergent_symbol` | `' 💥'` | Is displayed when commit is in [divergent](https://github.com/martinvonz/jj/blob/main/docs/glossary.md#divergent-change) state. |
| `format` | `'\[$symbol[$change_id_prefix]($change_id_prefix_style)[$change_id_suffix]($change_id_suffix_style) [$commit_id_prefix]($commit_id_prefix_style)[$commit_id_suffix]($commit_id_suffix_style) on [$branch]($branch_style)$no_description_symbol$divergent_symbol\]'` | The format for rendering the module. `symbol`, `style`, and other variables can be included. |
| `disabled` | `false` | Disables the `jj` module. |
| `change_id_prefix_style` | `'purple'` | The style for uniq part of change id. |
| `change_id_suffix_style` | `'bright-black'` | The style for the rest of change id. |
| `commit_id_prefix_style` | `'blue'` | The style for unique part of commit hash. |
| `commit_id_suffix_style` | `'bright-black'` | The style for the rest of commit hash. |
| `truncation_length` | `8` | Truncates the commit and change id to `truncation_length` characters. |
| `branch_style` | `'purple'` | The style for the branch name. |

### Variables

```
[🍐 rnyynlop 811ca1a4 on push-rnyynlopprno*]
```

| Variable | Example | Description |
| ------------------ | --------- | ----------------------------------------------------------------- |
| `symbol` | `🍐` | Mirrors the value of option `symbol`. |
| `change_id_prefix` | `r` | Unique part of the change id, styled by `change_id_prefix_style`. |
| `change_id_suffix` | `nyynlop` | The rest of the change id, styled by `change_id_suffix_style`. |
| `commit_id_prefix` | `811` | Unique part of the commit id, styled by `commit_id_prefix_style`. |
| `commit_id_suffix` | `ca1a4` | The rest of the commit id, styled by `commit_id_suffix_style`. |
| `branch` | `master` | The current branch name. |

### Example

```toml
# ~/.config/starship.toml

[jj]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[jj]
[jj_status]

The docs here are out of sync with the code. Also needs changing in the initial prose.

symbol = "🍐 "
style = "purple"
format = "\\[$symbol[$change_id_prefix]($change_id_prefix_style)[$change_id_suffix]($change_id_suffix_style) [$commit_id_prefix]($commit_id_prefix_style)[$commit_id_suffix]($commit_id_suffix_style) on [$branch]($branch_style)$no_description_symbol$divergent_symbol\\]"
disabled = false
change_id_prefix_style = "purple"
change_id_suffix_style = "bright-black"
commit_id_prefix_style = "blue"
commit_id_suffix_style = "bright-black"
truncation_length = 8
no_description_symbol = "📝"
divergent_symbol = "💥"
branch_style = "purple"
```

## Julia

The `julia` module shows the currently installed version of [Julia](https://julialang.org/).
Expand Down
40 changes: 40 additions & 0 deletions src/configs/jj.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Deserialize, Serialize, Debug)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct JJConfig<'a> {
pub symbol: &'a str,
pub format: &'a str,
pub disabled: bool,
pub change_id_prefix_style: &'a str,
pub change_id_suffix_style: &'a str,
pub commit_id_prefix_style: &'a str,
pub commit_id_suffix_style: &'a str,
pub truncation_length: u8,
pub no_description_symbol: &'a str,
pub divergent_symbol: &'a str,
pub branch_style: &'a str,
}

impl<'a> Default for JJConfig<'a> {
fn default() -> Self {
JJConfig {
symbol: "🍐 ",
format: "\\[$symbol[$change_id_prefix]($change_id_prefix_style)[$change_id_suffix]($change_id_suffix_style) [$commit_id_prefix]($commit_id_prefix_style)[$commit_id_suffix]($commit_id_suffix_style) on [$branch]($branch_style)$no_description_symbol$divergent_symbol\\]",
disabled: false,
change_id_prefix_style: "purple", // magenta
change_id_suffix_style: "bright-black",
commit_id_prefix_style: "blue",
commit_id_suffix_style: "bright-black",
truncation_length: 8,
no_description_symbol: " 📝",
divergent_symbol: " 💥",
branch_style: "purple",
}
}
}
3 changes: 3 additions & 0 deletions src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub mod helm;
pub mod hg_branch;
pub mod hostname;
pub mod java;
pub mod jj;
pub mod jobs;
pub mod julia;
pub mod kotlin;
Expand Down Expand Up @@ -196,6 +197,8 @@ pub struct FullConfig<'a> {
#[serde(borrow)]
java: java::JavaConfig<'a>,
#[serde(borrow)]
jj_status: jj::JJConfig<'a>,
#[serde(borrow)]
jobs: jobs::JobsConfig<'a>,
#[serde(borrow)]
julia: julia::JuliaConfig<'a>,
Expand Down
1 change: 1 addition & 0 deletions src/configs/starship_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub const PROMPT_ORDER: &[&str] = &[
"vcsh",
"fossil_branch",
"fossil_metrics",
"jj_status",
"git_branch",
"git_commit",
"git_state",
Expand Down
1 change: 1 addition & 0 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub const ALL_MODULES: &[&str] = &[
"hg_branch",
"hostname",
"java",
"jj_status",
"jobs",
"julia",
"kotlin",
Expand Down