feat: add configurable diff command with $width and interactive support#453
feat: add configurable diff command with $width and interactive support#453pablospe wants to merge 5 commits intoidursun:mainfrom
Conversation
Add a new placeholder variable $width that exposes the actual view width (in columns) to preview commands. This enables tools like delta to use --side-by-side with the correct width. Similar to how fzf exposes $FZF_PREVIEW_COLUMNS, this allows users to configure preview commands that adapt to the view size: ```toml [preview] revision_command = ["util", "exec", "--", "bash", "-c", """jj show --color always --git -r $change_id | delta --side-by-side --width $width"""] ``` The width updates dynamically when the preview pane is resized.
|
fyi the issue with delta side-by-side has a workaround as discussed in #314 (comment) linting is failing, please run go fmt |
Add a new [diff] config section with a customizable command for the built-in diff view (d key on files). This allows users to use tools like delta with proper width support. The screen width is passed via $width placeholder, enabling side-by-side diff viewers to use the correct terminal width. Example configuration: ```toml [diff] command = ["util", "exec", "--", "bash", "-c", """jj diff --color always --git -r $change_id $file | delta --side-by-side --width $width"""] ``` Available placeholders: $change_id, $commit_id, $file, $width
887391f to
472d522
Compare
|
Thank! Let me explain a bit better what is the problem. When pressing
The workaround in #314 avoids the problem by disabling side-by-side mode entirely ( This PR solves it properly by:
This lets you use delta with |
|
Hey thanks, This side by side diff issue when using delta is coming up regularly and at this point I am just ignoring it. I don't feel comfortable adding a configuration block just to enable integration one of the tools out there. My take on this is that; If you want to use a custom pager for diffs, you can unbind the |
hey @pablospe , i'm using delta side-by-side with no issue at all, using the config suggested in #314 ,
|
|
@baggiiiie Thanks! One question. Is this working for you when you enter to delta from |
display works fine when showing diff from file list, tho it's only display, losing pager's other functionalities (regarding pager, related discussion see #366 ) |
Yes, exactly, thanks for the video and the confirmation. I thought I was missing something. This is exactly what I noticed and wanted to solve with this PR, which allow me to have the full delta experience with n/N navigation (pager functionalities). |
@idursun [keys]
diff = []
[keys.details]
diff = []
[custom_commands.deltadiff]
key = ["d"]
args = ["util", "exec", "--", "bash", "-c", "jj diff --git --color always -r $change_id $file | delta --pager 'less -R +g'"]
show = "interactive"but it doesn't seem to be working:
|
|
@idursun ignore my previous message. I found a solution for what I wanted to achieve with this PR, I think the inline format made the difference (somehow). In jjui config file: # Unbind built-in diff key to allow custom command to handle it
[keys]
diff = []
# Interactive diff with delta (works in both revision list and details view)
# - $change_id: replaced with selected revision
# - $file: replaced with selected file (in details view) or empty (in revision view)
# - show = "interactive": opens real terminal so delta's pager/navigation works
[custom_commands]
"deltadiff" = { key = ["d"], args = ["util", "exec", "--", "bash", "-c", "jj diff --git --color always -r $change_id $file | delta --pager 'less -R +g'"], show = "interactive" }@baggiiiie Could you give a try to this? It will give you the pager's functionalities. And you don't need to touch .gitconfig and jj/config anymore, only jjui/config. |
|
@pablospe nice thanks, your custom command works! |
|
Ok, we can close this PR. Thanks for the help both and the very useful tool, @idursun and @baggiiiie. |

Summary
[diff]config section with customizablecommandfor the built-in diff view (d key on files)show = "interactive"to open diff in a real terminal (like custom commands)$widthplaceholder for proper side-by-side diff renderingMotivation
When using delta with
--side-by-sidein the built-in diff view, there was no way to:This complements the
$widthvariable added for preview commands (#452).Example configuration
Available placeholders
$change_id- revision change ID$commit_id- revision commit ID$file- selected file path$width- screen width in columns