forgit: Delta side-by-side not displayed correctly on fzf preview window

Check list

  • I have read through the README
  • I have the latest version of forgit
  • I have searched through the existing issues

Environment info

  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:
  • Shell
    • bash
    • zsh
    • fish

Problem / Steps to reproduce

I have been using forgit for a while and so far I love it! A while ago I switched to delta to display the diff however if I toggle the side-to-side option in delta in the preview window looks all squished to the left of the preview window with very narrow panels for each side of the diff. However, this only happens in forgit as if I run git diff I see the side to side no problems spanning the whole window. (I attached a screenshot)

DeepinScreenshot_select-area_20201031111037

Am I missing something here? Is this a fzf option maybe? I have been looking for days and I cannot find anything 😅

Thank you for your help in advance, I love this tool very much, keep up the good work!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 25 (4 by maintainers)

Commits related to this issue

Most upvoted comments

A workaround based on @Kr1ss-XD 's comment:

NOTE I’ve just noticed a paragraph in the fzf(1) manual, which might be relevant for this ticket :

fzf exports $FZF_PREVIEW_LINES and $FZF_PREVIEW_COLUMNS so that they represent the exact size of the preview window. (It also overrides $LINES and $COLUMNS with the same values but they can be reset by the default shell, so prefer to refer to the ones with FZF_PREVIEW_ prefix.)

It’s in the “Preview” section.

export FORGIT_PAGER='delta --side-by-side -w ${FZF_PREVIEW_COLUMNS:-$COLUMNS}' 

2020 11 11-19 28 12 screenshot

<strike>The only cons of this solution is it need to be set manually instead of reading from git’s config automatically. </strike>

EDIT: You can also make it work by changing git’s config:

pager = delta --side-by-side -w ${FZF_PREVIEW_COLUMNS:-$COLUMNS}

@mrswats @crivotz

@wfxr this worked for me

[core]
pager = bash -c 'delta --side-by-side --width ${FZF_PREVIEW_COLUMNS:-$COLUMNS}'

it seems that git uses sh to run this command, and ${var:-word} is a bashism, so this explicitly uses bash

@mrswats Thanks for your help and suggestion. I will pin this issue (until it gets fixed more elgantly) so that others with the same problem will easily find the solution.

BTW I like delta’s side-by-side view but it is not suitable when the window is narrow. So I use the following config that can auto switch to the classic view when the with of window is less than 160. Hope it can help you too.

pager = "{ [ $COLUMNS -lt 160 ] && delta || delta --side-by-side -w ${FZF_PREVIEW_COLUMNS:-$COLUMNS}; }"

EDIT: A little more complicated but better config:

pager = "{                                                           \
    COLUMNS=$(tput cols);                                            \
    if [ $COLUMNS -ge 80 ] && [ -z $FZF_PREVIEW_COLUMNS ]; then      \
        delta --side-by-side -w $COLUMNS;                            \
    elif [ $COLUMNS -ge 160 ] && [ ! -z $FZF_PREVIEW_COLUMNS ]; then \
        delta --side-by-side -w $FZF_PREVIEW_COLUMNS;                \
    else                                                             \
        delta;                                                       \
    fi                                                               \
}"

Nice ! If that is the issue, it might also suffice to simply omit the : :

[core]
	pager	=	delta --side-by-side --width ${FZF_PREVIEW_COLUMNS-$COLUMNS}

I think that’s valid sh syntax. Not tested though - I’m on mobile right now.

Okay, just right after comenting the other issue the first open issue in delta is this one: https://github.com/dandavison/delta/issues/368 which is exactly the issue I reported.

@0xRZ Have you exported your FZF_PREVIEW_COLUMNS and COLUMNS variables? Otherwise forgit has no access to them.

This solution stopped working for me on fzf 0.35.1, delta 0.15.1: pager = delta --width ${FZF_PREVIEW_COLUMNS-$COLUMNS}

It says error: The argument '--width <N>' requires a value but none was supplied when trying to open diff with forgit::diff