Starship - jj-vcs/jj GitHub Wiki
Configuring Starship to call jj
https://starship.rs/ is a cross-shell prompt.
Basic prompt
For some info about the jj change you are currently at you can use:
[custom.jj]
command = '''
jj log --revisions @ --limit 1 --ignore-working-copy --no-graph --color always --template '
separate(" ",
bookmarks.map(|x| truncate_end(10, x.name(), "…")).join(" "),
tags.map(|x| truncate_end(10, x.name(), "…")).join(" "),
surround("\"", "\"", truncate_end(24, description.first_line(), "…")),
if(conflict, "conflict"),
if(divergent, "divergent"),
if(hidden, "hidden"),
)
'
'''
when = "jj --ignore-working-copy root"
symbol = "jj"
[custom.jjstate]
when = "jj --ignore-working-copy root"
command = '''
jj log -r@ -n1 --ignore-working-copy --no-graph -T "" --stat | tail -n1 | sd "(\d+) files? changed, (\d+) insertions?\(\+\), (\d+) deletions?\(-\)" ' ${1}m ${2}+ ${3}-' | sd " 0." ""
'''
[!TIP]
This is partially inspired by the Fish Shell prompt example. This is a quick solution, feel free to improve on it and share your improvements.
Example screenshot:
Alternative prompt
This prompt uses more emojis and also disables Git modules when JJ is found:
# custom module for jj status
[custom.jj]
description = "The current jj status"
when = "jj --ignore-working-copy root"
symbol = "🥋 "
command = '''
jj log --revisions @ --no-graph --ignore-working-copy --color always --limit 1 --template '
separate(" ",
change_id.shortest(4),
bookmarks,
"|",
concat(
if(conflict, "💥"),
if(divergent, "🚧"),
if(hidden, "👻"),
if(immutable, "🔒"),
),
raw_escape_sequence("\x1b[1;32m") ++ if(empty, "(empty)"),
raw_escape_sequence("\x1b[1;32m") ++ coalesce(
truncate_end(29, description.first_line(), "…"),
"(no description set)",
) ++ raw_escape_sequence("\x1b[0m"),
)
'
'''
# optionally disable git modules when JJ is found.
# note that you'll need to add ${custom.git_branch}, ${custom.git_commit} etc
# into format: https://starship.rs/config/#default-prompt-format
[git_status]
disabled = true
[custom.git_status]
when = "! jj --ignore-working-copy root" # Slow without `require_repo = true`
require_repo = true # Avoids `when` eval overhead in plain dirs
command = "starship module git_status"
style = "" # This disables the default "(bold green)" style
description = "Only show git_status if we're not in a jj repo"
[git_commit]
disabled = true
[custom.git_commit]
when = "! jj --ignore-working-copy root"
require_repo = true
command = "starship module git_commit"
style = ""
description = "Only show git_commit if we're not in a jj repo"
[git_metrics]
disabled = true
[custom.git_metrics]
when = "! jj --ignore-working-copy root"
require_repo = true
command = "starship module git_metrics"
description = "Only show git_metrics if we're not in a jj repo"
style = ""
[git_branch]
disabled = true
[custom.git_branch]
when = "! jj --ignore-working-copy root"
require_repo = true
command = "starship module git_branch"
description = "Only show git_branch if we're not in a jj repo"
style = ""
Example screenshot:
Performance tips
-
--ignore-working-copy. The commands above use ajj --ignore-working-copyflag. This tellsjjnot to update its snapshot of the working copy, and improves performance of the prompt. -
detect_folders. Thewhen = "jj --ignore-working-copy root"config requires a shell invocation, which has performance overhead. The overhead is small (~12 ms on a MacBook Pro with M2) but not zero. If you’d like to avoid it, usedetect_foldersinstead (but note that the JJ prompt will only be shown in the root of the repo, then):- when = "jj --ignore-working-copy root" + detect_folders = [".jj"] -
Faster location of .jj directory: Instead of using
jj --ignore-working-copy rootto test for being in a jj workspace, the following is about 5-10x faster on my system:when = "while ! test -d .jj; do test $PWD = / && exit 1; cd -P ..; done; exit 0"Swap theexit 1andexit 0to invert the test for thecustom.git*entries -
Don't search for the
.jjdirectory if not in a git repositoryrequire_repo = truewill do this and is very fast (<1ms with a warm cache on my machine)- everybody should set this for the
custom.git*entries to speed things - If you only use git colocated workspaces (default since 0.34) you can set this for the
custom.jjentry as well.- Downside is you won't get jj prompts for non-colocated workspaces
- Also there are 4
custom.git*entries, but only onecustom.jjentry, so you get 80% of the performance benefit without this.
-
shell. Starship defaults to using the parent shell for custom modules. Depending on the shell in use, using a more minimal shell and avoiding shell init sourcing can be much faster.+ shell = ["sh", "--norc", "--noprofile"]
Using starship-jj in Starship
starship-jj uses the jj-cli crate to have better performance than having multiple jj invocations in your starship.toml
https://gitlab.com/lanastara_foss/starship-jj
install via
cargo install starship-jj --locked
and add it to your starship.toml
# Extend the default format config: https://starship.rs/config/#default-prompt-format
format="""
...
${custom.jj}\
...
"""
#...
[custom.jj]
command = "prompt"
format = "$output"
ignore_timeout = true
shell = ["starship-jj", "--ignore-working-copy", "starship"]
use_stdin = false
when = true