Last active
April 6, 2024 20:25
-
-
Save chooglen/c76b2a6950aade154408fad2c42f97d7 to your computer and use it in GitHub Desktop.
Interactive `jj` with `fzf`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2022 Google LLC. | |
# SPDX-License-Identifier: Apache-2.0 | |
export FZF_MOVEMENT="--bind='ctrl-n:preview-down' \ | |
--bind='ctrl-p:preview-up'" | |
export FZF_DEFAULT_OPTS="$FZF_MOVEMENT" | |
jjl() { | |
_getCandidates="jj log $@" | |
_reload="toggle-preview+reload($_getCandidates)+toggle-preview" | |
_jjLogLineToCommitId="echo {} | grep -o '[a-f0-9]\{7,\} ' | sed '1q;d' | tr -d '\n'" | |
_jjLogLineToChangeId="echo {} | grep -o '[a-f0-9]\{7,\} ' | sed '2q;d' | tr -d '\n'" | |
_show="$_jjLogLineToCommitId | xargs -I % jj show --color=always %" | |
_show_git="$_jjLogLineToCommitId | xargs -I % jj show --color=always --git %" | |
_squash="$_jjLogLineToCommitId | xargs -I % jj squash -r %" | |
_edit="$_jjLogLineToCommitId | xargs -I % jj edit %" | |
_checkout="$_jjLogLineToCommitId | xargs -I % jj checkout %" | |
# Passing the --disabled flag disables the fuzzy-search, which lets you | |
# input whatever you want into the query e.g. you can use the query as a | |
# command builder for invocations like `jj rebase -s A -d B`. | |
eval $_getCandidates | \ | |
fzf --ansi --no-sort --reverse --tiebreak=index --disabled \ | |
--preview="$_show" \ | |
--bind "ctrl-r:reload($_getCandidates)" \ | |
--bind "ctrl-o:execute-silent:($_jjLogLineToCommitId | pbcopy)" \ | |
--bind "ctrl-h:execute-silent($_jjLogLineToChangeId | pbcopy)" \ | |
--bind "alt-s:execute-silent($_squash)+$_reload" \ | |
--bind "alt-e:execute-silent($_edit)+$_reload" \ | |
--bind "alt-c:execute-silent($_checkout)+$_reload" \ | |
--bind "ctrl-c:cancel" \ | |
--bind "ctrl-y:execute-silent(echo -n {q} | pbcopy)" \ | |
--bind "enter:execute-silent(eval {q})+$_reload" | |
} |
Since the last comment, I've amended this to make it easier to build and run jj commands, e.g. adding enter
to evaluate the current query. I use this as a long-running interactive jj client, so I intentionally avoid aborting this process.
I use this as a long-running interactive jj client, so I intentionally avoid aborting this process.
Yup, that makes sense, just made the comment in case someone finds that more useful. Regardless, I might also give it a try as a long-running client, see how that feels 😃
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is really useful, thanks!
A couple of changes I made, that may be useful for others:
reload($_getCandidates)
withabort
to exit fzf after checking out the new commit.enter
that does the same thing asalt-e
for convenience.