git:glog: Respect file arguments when previewing
When file arguments were passes behind `--`, show only these files in the patch preview. This mimics the behaviour of `git log -up -- <files>`. The full patch can still be displayed with ctrl-p.
This commit is contained in:
@@ -56,9 +56,16 @@ read -r -d '' <<EOT
|
|||||||
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
|
git show "${(j:%n:)format}" "$date" --color=always --patch-with-stat "\$out"
|
||||||
EOT
|
EOT
|
||||||
fzf_preview[patch]="$fzf_preview[construct] { $REPLY"
|
fzf_preview[patch]="$fzf_preview[construct] { $REPLY"
|
||||||
(( ! $+commands[diff-so-fancy] )) ||
|
# Get file arguments after (and including) `--` and wrap each in double quotes
|
||||||
|
fzf_preview[files_only]="$fzf_preview[patch] ${(@)${@:${@[(ei)--]}}/(#m)*/\"$MATCH\"}"
|
||||||
|
|
||||||
|
if (( $+commands[diff-so-fancy] )); then
|
||||||
fzf_preview[patch]+=" | diff-so-fancy --color=always"
|
fzf_preview[patch]+=" | diff-so-fancy --color=always"
|
||||||
|
fzf_preview[files_only]+=" | diff-so-fancy --color=always"
|
||||||
|
fi
|
||||||
|
|
||||||
fzf_preview[patch]+="; }"
|
fzf_preview[patch]+="; }"
|
||||||
|
fzf_preview[files_only]+="; }"
|
||||||
|
|
||||||
read -r -d '' <<EOT
|
read -r -d '' <<EOT
|
||||||
git show "${(j:%n:)format}" "$date" --color=always --stat "\$out"
|
git show "${(j:%n:)format}" "$date" --color=always --stat "\$out"
|
||||||
@@ -88,6 +95,8 @@ local -A binds=(
|
|||||||
"ctrl-s" "preview($fzf_preview[stat])"
|
"ctrl-s" "preview($fzf_preview[stat])"
|
||||||
# Preview patch
|
# Preview patch
|
||||||
"ctrl-p" "preview($fzf_preview[patch])"
|
"ctrl-p" "preview($fzf_preview[patch])"
|
||||||
|
# Files only
|
||||||
|
"ctrl-f" "preview($fzf_preview[files_only])"
|
||||||
# faster navigation
|
# faster navigation
|
||||||
"home" "first"
|
"home" "first"
|
||||||
"end" "last"
|
"end" "last"
|
||||||
@@ -100,7 +109,7 @@ local -a fzf_args=(
|
|||||||
# Expand the binds array in the format "key1:value1,key2:value2".
|
# Expand the binds array in the format "key1:value1,key2:value2".
|
||||||
"--bind" "${(@kj:,:)binds/(#m)*/$MATCH:$binds[$MATCH]}"
|
"--bind" "${(@kj:,:)binds/(#m)*/$MATCH:$binds[$MATCH]}"
|
||||||
# Execute git show on the commit as preview.
|
# Execute git show on the commit as preview.
|
||||||
"--preview" "$fzf_preview[patch]"
|
"--preview" "$fzf_preview[files_only]"
|
||||||
# Reverse the layout so that the newest commit is at the top.
|
# Reverse the layout so that the newest commit is at the top.
|
||||||
"--reverse"
|
"--reverse"
|
||||||
# Do not sort when typing to maintain the sorting by date.
|
# Do not sort when typing to maintain the sorting by date.
|
||||||
|
|||||||
Reference in New Issue
Block a user