jjj
jjj
Several jujutsu commands require a revset. When I am hacking on a project, I tend to poke at multiple stacks simultaneously. Many of these stacks use a generated bookmark name. Identifying them becomes a bit tricky after a while, so I’ve created a little script with fzf, called jjj (jujutsu jump i suppose), to help me select revsets:
许多 Jujutsu 命令都需要一个修订集(revset)。当我在进行项目开发时,往往会同时处理多个堆栈。这些堆栈中有很多使用自动生成的书签名称,时间久了很难辨认。因此,我用 fzf 写了一个名为 jjj(我猜是 jujutsu jump 的缩写)的小脚本,用来帮我选择修订集:
cmd="${1:-show}"
shift
selected=$( jj log -r 'all()' --color=always \
| fzf \
--min-height=15 \
--cycle \
--ansi \
--prompt "jj $cmd> " ) || exit 0
rev=$(echo "$selected" | awk '{for(i=1;i<=NF;i++) if(length($i)>=7){print $i; exit}}')
jj "$cmd" -r "$rev" "$@"
jjj is exactly like jj, except your revset selection happens inside fzf. Every other arg is just passed straight through. This opens up jj log in an fzf window:
jjj 的用法和 jj 完全一样,区别在于你可以在 fzf 中选择修订集。其他所有参数都会直接传递给 jj。运行它会在 fzf 窗口中打开 jj log:
$ jjj new
jj new> 4774/4774 @ srppunpn (empty) (no description set) default@ 2h
> • qknsmttw knotserver: remove `--allow-empty` from `git am`..
• lqvzlslt knotserver: calculate old/new SHAs in merge 2h
│ · lqvzlslt knotserver: calculate old/new SHAs in merge op..
├─╯
• xqwtwoxr appview,blog: add twitter link to footer 20h
• vsrmrrlt knotserver/xrpc: emit `refUpdate` event on `repo..
• orsknlnx knotserver/git: allow applying empty patches 20h
│ • xqwtwoxr appview,blog: add twitter link to footer icy/x..
├─╯
• nrrqukxt ogre: center align footer items 21h
│ · llvrxstp appview/timeline: announce vouching in timelin..
│ · uztumlpw appview/pages: add vouch hats 20h
│ · urzpovyu appview/state: add vouch handlers 20h
│ · xwysqnul appview/ingester: ingest vouch records 23h
│ · vrpmqwpu appview/{db,models}: add table and models for ..
│ · oswtmkqr lexicons: add vouch lexicon 1d
├─╯
│ · lxrslzty (empty) (no description set) 1d
│ · nzqqortv knotserver: limit request size op/nzqqortvpnzz..
You can filter by typing a keyword, say, “vouch” in my case:
你可以通过输入关键字进行过滤,比如我输入 “vouch”:
$ jjj new
jj new> vouch
515/4774 >
│ · oswtmkqr lexicons: add vouch lexicon 1d
│ · uztumlpw appview/pages: add vouch hats 20h
│ · urzpovyu appview/state: add vouch handlers 20h
│ · xwysqnul appview/ingester: ingest vouch records 23h
..u appview/{db,models}: add table and models for vouching 23h
│ · llvrxstp appview/timeline: announce vouching in timelin..
• vouqlrtz improve branch-pr ux branch-prs-2 1y
• vxozrylw deps: use fork of chroma 11mo
• vwknkkmt fix default value for resubmitCheck 1y
• vnxlozsk feature: ability to change default branch for a ..
..ysx knotserver: have top level router use cors header func..
Hitting enter simply substitutes that rev into a jj new command:
按下回车键,它会自动将选中的修订 ID 替换到 jj new 命令中:
$ jjj new
# perform a selection in fzf
$ jj new -r oswtmkqr
You could use any jj command really:
实际上,你可以将其用于任何 jj 命令:
$ jjj edit
$ jjj show
$ jjj evolog -p
This is because almost all jj commands accept a revset using the -r flag:
这是因为几乎所有的 jj 命令都支持通过 -r 标志来接受修订集:
$ jj show --help
. . .
Arguments:
[REVSET] Show changes in this revision, compared to its parent(s) [default: @]
[aliases: -r]
You can add a preview window, to view the patch for each change, with these flags:
你可以添加一个预览窗口,通过以下标志来查看每个变更的补丁:
--preview 'echo {} | awk "{for(i=1;i<=NF;i++) if(length(\$i)>=7){print \$i; exit}}" | xargs jj show --color=always ' \
--preview-window=right:60% \
Note that the jjj is tuned to my log template. It requires that your log output be one-line per change and that you print a full 7+ character change-id in the log. Mutate as required.
请注意,jjj 是根据我的日志模板调整的。它要求你的日志输出格式为每个变更占一行,并且在日志中打印出完整的 7 位及以上字符的变更 ID(change-id)。你可以根据需要进行修改。