junegunn / fzf-git.sh

bash and zsh key bindings for Git objects, powered by fzf
612 stars 53 forks source link

Space character in filename causes git files preview error #25

Open vinhant opened 1 year ago

vinhant commented 1 year ago

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

junegunn commented 5 months ago

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