Skip to content

Instantly share code, notes, and snippets.

@hroi
Last active December 29, 2024 02:41
Show Gist options
  • Save hroi/d0dc0e95221af858ee129fd66251897e to your computer and use it in GitHub Desktop.
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`
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
@pkulak
Copy link

pkulak commented Nov 13, 2024

Heads up that line 22 got changed to bookmarks.join(", "), in recent versions.

@markstos
Copy link

Could you provide a more complete example that shows a jj bookmark in a JJ repo, but otherwise shows a Git branch in a git repo.

@hroi
Copy link
Author

hroi commented Nov 18, 2024

Heads up that line 22 got changed to bookmarks.join(", "), in recent versions.

Done.

@hroi
Copy link
Author

hroi commented Nov 18, 2024

Could you provide a more complete example that shows a jj bookmark in a JJ repo, but otherwise shows a Git branch in a git repo.

The fish_vcs_prompt function that is distributed with fish tries the different prompt generators in order. It is called from fish_prompt. Edit it with funced fish_vcs_prompt.

Mine looks like this:

function fish_vcs_prompt --description "Print all vcs prompts"
    # If a prompt succeeded, we assume that it's printed the correct info.
    # This is so we don't try svn if git already worked.
    fish_jj_prompt $argv
    or fish_git_prompt $argv
    or fish_hg_prompt $argv
    or fish_fossil_prompt $argv
    # The svn prompt is disabled by default because it's quite slow on common svn repositories.
    # To enable it uncomment it.
    # You can also only use it in specific directories by checking $PWD.
    # or fish_svn_prompt
end

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