Closed dslgr closed 2 years ago
I've had some trouble with getting this to work from within PSFzf but this is along the lines of what I'm thinking. The one other thing I'd prefer this function do is print out the selections. I'm very new to writing powershell, so this might be written unusually. This did require installing sed as well.
function fsa {
$gitRoot = git rev-parse --show-toplevel
git status --porcelain | `
sed -E 's/^ ?[^ ]+ +(.*)/\1/' | `
sed -e 's/\"//g' | % `
{Join-Path -Path $gitRoot -ChildPath $_} | `
fzf -m --preview 'git diff --color=always -- {}' | % `
{git add $_ }
}
And this version removes files that were already added as well as using delta. (Utilizing ripgrep as well.)
function fsa {
$gitRoot = git rev-parse --show-toplevel
git status --porcelain | `
# remove files that were already added
rg '^\W.' | `
# parse the filenames from git status
sed -E 's/^ ?[^ ]+ +(.*)/\1/' | `
# remove any quotation marks from files with spaces
sed -e 's/\"//g' | % `
{Join-Path -Path $gitRoot -ChildPath $_} | `
# fzf -m --preview 'git diff --color=always -- {} | delta' | % `
Invoke-Fzf -Multi -Ansi -Preview "git diff --color=always -- {} | delta" | % `
{git add $_ }
}
If you don't mind a little bit of cheating, I mapped the functions here to be used with PowerShell using git bash to execute the commands.
https://github.com/DanSM-5/user-configuration/blob/master/utils/fzf-git.psm1
The fuzzy git status sounds similar to the fgf
function.
Sounds like that should work! I will mention that if I run Invoke-PsFzfGitFiles I get some strange behavior where git bash windows keep opening and closing. I'm using Windows Terminal if that matters. Maybe there's a setting to have git bash run silently.
Hi! Is there a way for Invoke-FuzzyGitStatus to bring up a preview window? The ideal would be a preview with a diff for the file. I'm thinking something like this but in powershell (https://github.com/wfxr/forgit). That would be a really helpful way to preview a git add. It might also be helpful to have something in the readme about how to git add with Invoke-FuzzyGitStatus. I found
Invoke-FuzzyGitStatus | % { git add $_ }
from this page (https://www.brandonpugh.com/blog/2022/03/an-assortment-of-productivity-tips/).For the preview I tried adding different --preview options after Invoke-FuzzyGitStatus but that didn't seem to work. I am using fzf v29 and PSFzf v2.4.0.