Merge pull request #226 from carlfriedrich/support-stashes-in-gd

Support stashes in forgit::diff
This commit is contained in:
Wenxuan 2022-08-15 10:13:34 +08:00 committed by GitHub
commit 85bc57a15c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -119,8 +119,14 @@ function forgit::diff -d "git diff viewer" --argument-names arg1 arg2
end
end
set preview_cmd "forgit::extract_file {} | xargs -I% git diff --color=always -U$forgit_preview_context $commits -- % | $forgit_diff_pager"
set enter_cmd "forgit::extract_file {} | xargs -I% git diff --color=always -U$forgit_fullscreen_context $commits -- % | $forgit_diff_pager"
# Git stashes are named "stash@{x}", which contains the fzf placeholder "{x}".
# In order to support passing stashes as arguments to forgit::diff, we have to
# prevent fzf from interpreting this substring by escaping the opening bracket.
# The string is evaluated a few subsequent times, so we need multiple escapes.
set escaped_commits (echo $commits | sed 's/{/\\\\\\\\{/g')
set preview_cmd "forgit::extract_file {} | xargs -I% git diff --color=always -U$forgit_preview_context $escaped_commits -- % | $forgit_diff_pager"
set enter_cmd "forgit::extract_file {} | xargs -I% git diff --color=always -U$forgit_fullscreen_context $escaped_commits -- % | $forgit_diff_pager"
set opts "
$FORGIT_FZF_DEFAULT_OPTS

View file

@ -71,8 +71,13 @@ forgit::diff() {
}
repo="$(git rev-parse --show-toplevel)"
get_files="cd '$repo' && echo {} | sed 's/.*] *//' | sed 's/ -> / /'"
preview_cmd="$get_files | xargs -I% git diff --color=always -U$forgit_preview_context $commits -- % | $forgit_diff_pager"
enter_cmd="$get_files | xargs -I% git diff --color=always -U$forgit_fullscreen_context $commits -- % | $forgit_diff_pager"
# Git stashes are named "stash@{x}", which contains the fzf placeholder "{x}".
# In order to support passing stashes as arguments to forgit::diff, we have to
# prevent fzf from interpreting this substring by escaping the opening bracket.
# The string is evaluated a few subsequent times, so we need multiple escapes.
escaped_commits=${commits//\{/\\\\\{}
preview_cmd="$get_files | xargs -I% git diff --color=always -U$forgit_preview_context $escaped_commits -- % | $forgit_diff_pager"
enter_cmd="$get_files | xargs -I% git diff --color=always -U$forgit_fullscreen_context $escaped_commits -- % | $forgit_diff_pager"
opts="
$FORGIT_FZF_DEFAULT_OPTS
+m -0 --bind=\"enter:execute($enter_cmd | $forgit_enter_pager)\"