fzf-git.sh
fzf-git.sh copied to clipboard
Space character in filename causes git files preview error
The "git files" preview command uses {-1} which creates an issue if the filename has space characters in it. e.g. if filename is "two words" then {-1} will return words"
I tried fixing this by 1. using {2..} which skips the git status flag and 2. piping the output of "git ls-files" to sed 's/"\(.*\)"$/\1/' in order to remove the double-quotes from filenames. For example if git status is
M "two words" then the sed command will give M two words and then {2..} should give two words. Then the preview command should work because it adds its own single quote.
Other options I looked at is git ls-files -z but I don't know how to send that to fzf
Using -z along with --read0 is the only option, but unfortunately, that disables colored output.
# Colors
git -c color.status=always status --short --no-branch | fzf --ansi
# No colors
git -c color.status=always status -z --short --no-branch | fzf --read0 --ansi
git -c color.status=always status -z --short --no-branch | fzf --read0 --ansi
It was a bug in git, reported and possibly fixed in a future release.
https://lore.kernel.org/git/XCDlwEkTlgoZIyIf_8BfOGl1C3C63Ioxeib4BRNJ9Jm_CtYWKT3qu-pDaeXVtS1Ifq6E4pT9G0yDbIS_nSwN-uiBuBNAlMyrOv0R1RyM7oc=@protonmail.com/T/#u
EDIT 1 EDIT 2: Replace github mirror links with git.kernel.org (because of rebase)
The patch is currently in the seen (as in 'seen' by the maintainer) branch:
- https://git.kernel.org/pub/scm/git/git.git/refs/
- https://git.kernel.org/pub/scm/git/git.git/commit/?id=50927f4f683a35ad1c76c8a02a1759a076d3f8f8
- https://lore.kernel.org/git/[email protected]/
I believe the next steps, if the patch is approved, would be:
next => master => Official Release (~ maybe end of this year?)
next=>master=> Official Release (~~maybe end of this year?~~)
Colors are applied correctly when the -z --short flags are used: 2.51.2 (26 Oct 2025)
- Ref: https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/RelNotes/2.51.2.adoc