Skip to content

Commit

Permalink
feat(module): add jj module to display repository status
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdeafbeef committed Mar 9, 2024
1 parent 3949697 commit d9acbbc
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 0 deletions.
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
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]
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

0 comments on commit d9acbbc

Please sign in to comment.