Skip to content

Instantly share code, notes, and snippets.

@hroi
Last active November 17, 2025 17:13
Show Gist options
  • Select an option

  • Save hroi/d0dc0e95221af858ee129fd66251897e to your computer and use it in GitHub Desktop.

Select an option

Save hroi/d0dc0e95221af858ee129fd66251897e to your computer and use it in GitHub Desktop.
Jujutsu (jj) prompt for fish-shell
# Place me in ~/.config/fish/functions
# Then add me to `fish_vcs_prompt`: `funced fish_vcs_prompt` and save it to
# your personal config: `funcsave fish_vcs_prompt;`
function fish_jj_prompt --description 'Write out the jj prompt'
# Is jj installed?
if not command -sq jj
return 1
end
# Are we in a jj repo?
if not jj root --quiet &>/dev/null
return 1
end
# Generate prompt
jj log --ignore-working-copy --no-graph --color always -r @ -T '
surround(
" (",
")",
separate(
" ",
bookmarks.join(", "),
coalesce(
surround(
"\"",
"\"",
if(
description.first_line().substr(0, 24).starts_with(description.first_line()),
description.first_line().substr(0, 24),
description.first_line().substr(0, 23) ++ "…"
)
),
"(no description set)"
),
change_id.shortest(),
commit_id.shortest(),
if(conflict, "(conflict)"),
if(empty, "(empty)"),
if(divergent, "(divergent)"),
if(hidden, "(hidden)"),
)
)
'
end
@camtheman256
Copy link

I love this! Thanks for making this, I forked yours and added some usage of the label function to closer match jj st, which adds colours to (empty) and (conflict).

https://gist.github.com/camtheman256/028aa2f1ced68cd435093a2d4680cf88

@silasjelley
Copy link

function fish_jj_prompt
    command -sq jj; or return 1
    set -l info (
        jj log --no-graph --ignore-working-copy --color=always --revisions @ --template '
                separate(" ",
                    bookmarks,
                    if(conflict, label("conflict", "conflict")),
                    if(divergent, label("divergent", "divergent")),
                    if(parents.len() > 1, label("merge", "merged")),
                    coalesce(
                        if(empty, label("empty", "empty")),
                        label("change", "change")
                    )
            )
        ' 2>/dev/null
    )
    or return 1

    # Check if there are unpushed changes
    set -l unpushed (
        jj log --no-graph --color=never \
            --revisions '::@- & ~::remote_bookmarks()' \
            --limit 1 | wc -l
    )
    if test $unpushed -gt 0
        set info "$info" (set_color yellow)""(set_color normal)
    end

    test -n "$info"; and printf ' (%s)' $info
end

I like being able to quickly see when I have unpushed changes, so here's a slight modification that shows a little arrow (↑) when remote branch is behind. No warranty; works on my machine :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment