Handle .gitconfig pager attribute.

The existing script handles the `core.pager` attribute, but does not
account for the `pager` attribute in git-config. Tools like
`diff-highlight` which ship with git recommend using the `pager`
attribute, and provide beautiful diffs.

I've made minor changes in the script to use these configuration
parameters if they are defined.

Ref: https://github.com/git/git/tree/master/contrib/diff-highlight
This commit is contained in:
Vedang Manerikar 2020-08-08 12:08:42 +05:30
parent 57224696a9
commit d41375abdd

View file

@ -13,7 +13,8 @@ forgit::log() {
forgit::inside_work_tree || return 1
local cmd opts graph files
files=$(sed -nE 's/.* -- (.*)/\1/p' <<< "$*") # extract files parameters for `git show` command
cmd="echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_pager"
forgit_show_pager=$(git config pager.show || echo "$forgit_pager")
cmd="echo {} |grep -Eo '[a-f0-9]+' |head -1 |xargs -I% git show --color=always % -- $files | $forgit_show_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s +m --tiebreak=index
@ -38,9 +39,9 @@ forgit::diff() {
files=("$@")
fi
}
forgit_diff_pager=$(git config pager.diff || echo "$forgit_pager")
repo="$(git rev-parse --show-toplevel)"
cmd="echo {} |sed 's/.*] //' |xargs -I% git diff --color=always $commit -- '$repo/%' |$forgit_pager"
cmd="echo {} |sed 's/.*] //' |xargs -I% git diff --color=always $commit -- '$repo/%' | $forgit_diff_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+m -0 --bind=\"enter:execute($cmd |LESS='-R' less)\"
@ -60,7 +61,7 @@ forgit::add() {
changed=$(git config --get-color color.status.changed red)
unmerged=$(git config --get-color color.status.unmerged red)
untracked=$(git config --get-color color.status.untracked red)
forgit_diff_pager=$(git config pager.diff || echo "$forgit_pager")
# NOTE: paths listed by 'git status -su' mixed with quoted and unquoted style
# remove indicators | remove original path for rename case | remove surrounding quotes
extract="
@ -70,9 +71,9 @@ forgit::add() {
preview="
file=\$(echo {} | $extract)
if (git status -s -- \$file | grep '^??') &>/dev/null; then # diff with /dev/null for untracked files
git diff --color=always --no-index -- /dev/null \$file | $forgit_pager | sed '2 s/added:/untracked:/'
git diff --color=always --no-index -- /dev/null \$file | $forgit_diff_pager | sed '2 s/added:/untracked:/'
else
git diff --color=always -- \$file | $forgit_pager
git diff --color=always -- \$file | $forgit_diff_pager
fi"
opts="
$FORGIT_FZF_DEFAULT_OPTS
@ -92,7 +93,8 @@ forgit::add() {
forgit::reset::head() {
forgit::inside_work_tree || return 1
local cmd files opts
cmd="git diff --cached --color=always -- {} | $forgit_pager "
forgit_diff_pager=$(git config pager.diff || echo "$forgit_pager")
cmd="git diff --cached --color=always -- {} | $forgit_diff_pager "
opts="
$FORGIT_FZF_DEFAULT_OPTS
-m -0
@ -107,7 +109,8 @@ forgit::reset::head() {
forgit::restore() {
forgit::inside_work_tree || return 1
local cmd files opts
cmd="git diff --color=always -- {} | $forgit_pager"
forgit_diff_pager=$(git config pager.diff || echo "$forgit_pager")
cmd="git diff --color=always -- {} | $forgit_diff_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
-m -0
@ -122,7 +125,8 @@ forgit::restore() {
forgit::stash::show() {
forgit::inside_work_tree || return 1
local cmd opts
cmd="echo {} |cut -d: -f1 |xargs -I% git stash show --color=always --ext-diff % |$forgit_pager"
forgit_diff_pager=$(git config pager.diff || echo "$forgit_pager")
cmd="echo {} |cut -d: -f1 |xargs -I% git stash show --color=always --ext-diff % |$forgit_diff_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+s +m -0 --tiebreak=index --bind=\"enter:execute($cmd | LESS='-R' less)\"