diff --git a/README.md b/README.md index 6684a05..478a16e 100644 --- a/README.md +++ b/README.md @@ -317,9 +317,14 @@ variables: | `FORGIT_BLAME_PAGER` | `git config pager.blame` _or_ `$FORGIT_PAGER` | | `FORGIT_IGNORE_PAGER` | `bat -l gitignore --color always` _or_ `cat` | | `FORGIT_ATTRIBUTES_PAGER` | `bat -l gitattributes --color always` _or_ `cat` | -| `FORGIT_PREVIEW_PAGER` | Normal pager resolution* | +| `FORGIT_ENTER_PAGER` | `less -R -+F -+E`1 | +| `FORGIT_PREVIEW_PAGER` | Normal pager resolution2 | -* If your pager is a TUI program (e.g., `diffnav`, `tig`), fzf preview panes will be blank because they run +1 `FORGIT_ENTER_PAGER` controls the full-screen pager opened by the Enter key. Its default inherits options +from `LESS`, enables safe ANSI color handling with `-R`, and disables `-F` and `-E` so the pager remains open for short +output. Setting `FORGIT_ENTER_PAGER` replaces the default command. + +2 If your pager is a TUI program (e.g., `diffnav`, `tig`), fzf preview panes will be blank because they run without a TTY. Set `FORGIT_PREVIEW_PAGER` to a non-interactive pager (e.g., `delta`) to fix this. When set, it overrides all other `FORGIT_*_PAGER` settings in fzf preview context. diff --git a/bin/git-forgit b/bin/git-forgit index 58ce16e..a3d74f8 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -171,7 +171,7 @@ _forgit_get_pager() { ignore) echo -n "${FORGIT_IGNORE_PAGER:-$(hash bat &>/dev/null && echo 'bat -l gitignore --color=always' || echo 'cat')}" ;; attributes) echo -n "${FORGIT_ATTRIBUTES_PAGER:-$(hash bat &>/dev/null && echo 'bat -l gitattributes --color=always' || echo 'cat')}" ;; blame) echo -n "${FORGIT_BLAME_PAGER:-$(git config pager.blame || _forgit_get_pager)}" ;; - enter) echo -n "${FORGIT_ENTER_PAGER:-"LESS='-r' less"}" ;; + enter) echo -n "${FORGIT_ENTER_PAGER:-"less -R -+F -+E"}" ;; *) echo "pager not found: $1" >&2 ;; esac } diff --git a/tests/pager.test.sh b/tests/pager.test.sh new file mode 100644 index 0000000..5f04943 --- /dev/null +++ b/tests/pager.test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +function set_up_before_script() { + source bin/git-forgit +} + +function less() { + printf 'LESS=%s\n' "$LESS" + printf 'ARGS=%s\n' "$*" +} + +function test_enter_pager_preserves_less_and_disables_automatic_exit() { + local actual + + actual=$(LESS="-F -E -X -S -N" _forgit_pager enter) + + assert_contains "LESS=-F -E -X -S -N" "$actual" + assert_contains "ARGS=-R -+F -+E" "$actual" +}