|
12 | 12 | # This gives users the choice to set aliases inside of their git config instead |
13 | 13 | # of their shell config if they prefer. |
14 | 14 |
|
| 15 | +# Set shell for fzf preview commands |
15 | 16 | # Disable shellcheck for "which", because it suggests "command -v xxx" instead, |
16 | 17 | # which is not a working replacement. |
17 | 18 | # See https://github.com/koalaman/shellcheck/issues/1162 |
18 | 19 | # shellcheck disable=2230 |
19 | | -SHELL="$(which bash)" # Set shell for fzf preview commands |
| 20 | +SHELL="$(which bash)" |
| 21 | +export SHELL |
20 | 22 |
|
21 | 23 | # Get absolute forgit path |
22 | 24 | FORGIT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)/$(basename -- "${BASH_SOURCE[0]}") |
@@ -112,14 +114,26 @@ _forgit_diff() { |
112 | 114 | fi |
113 | 115 | } |
114 | 116 | repo="$(git rev-parse --show-toplevel)" |
115 | | - get_files="cd '$repo' && echo {} | sed 's/.*] *//' | sed 's/ -> / /'" |
| 117 | + # Construct a null-terminated list of the filenames |
| 118 | + # The input looks like one of these lines: |
| 119 | + # [R100] file -> another file |
| 120 | + # [A] file with spaces |
| 121 | + # [D] oldfile |
| 122 | + # And we transform it to this representation for further usage with "xargs -0": |
| 123 | + # file\0another file\0 |
| 124 | + # file with spaces\0 |
| 125 | + # oldfile\0 |
| 126 | + # We have to do a two-step sed -> tr pipe because OSX's sed implementation does |
| 127 | + # not support the null-character directly. |
| 128 | + get_files="echo {} | sed 's/.*] *//' | sed 's/ -> /\\\n/' | tr '\\\n' '\\\0'" |
116 | 129 | # Git stashes are named "stash@{x}", which contains the fzf placeholder "{x}". |
117 | 130 | # In order to support passing stashes as arguments to _forgit_diff, we have to |
118 | 131 | # prevent fzf from interpreting this substring by escaping the opening bracket. |
119 | 132 | # The string is evaluated a few subsequent times, so we need multiple escapes. |
120 | 133 | escaped_commits=${commits//\{/\\\\\{} |
121 | | - preview_cmd="$get_files | xargs -I% git diff --color=always -U$_forgit_preview_context $escaped_commits -- % | $_forgit_diff_pager" |
122 | | - enter_cmd="$get_files | xargs -I% git diff --color=always -U$_forgit_fullscreen_context $escaped_commits -- % | $_forgit_diff_pager" |
| 134 | + git_diff="git diff --color=always $escaped_commits" |
| 135 | + preview_cmd="cd '$repo' && $get_files | xargs -0 $git_diff -U$_forgit_preview_context -- | $_forgit_diff_pager" |
| 136 | + enter_cmd="cd '$repo' && $get_files | xargs -0 $git_diff -U$_forgit_fullscreen_context -- | $_forgit_diff_pager" |
123 | 137 | opts=" |
124 | 138 | $FORGIT_FZF_DEFAULT_OPTS |
125 | 139 | +m -0 --bind=\"enter:execute($enter_cmd | $_forgit_enter_pager)\" |
|
0 commit comments