diff --git a/conf.d/forgit.plugin.fish b/conf.d/forgit.plugin.fish index 23a6683..84f0ed2 100644 --- a/conf.d/forgit.plugin.fish +++ b/conf.d/forgit.plugin.fish @@ -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 diff --git a/forgit.plugin.zsh b/forgit.plugin.zsh index a12a161..8658859 100755 --- a/forgit.plugin.zsh +++ b/forgit.plugin.zsh @@ -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)\"