PatrickF1 / fzf.fish

🔍🐟 Fzf plugin for Fish
MIT License
1.96k stars 78 forks source link

[Search git status] preview changed files #237

Closed NextAlone closed 2 years ago

NextAlone commented 2 years ago

Add a preview for the changed file

PatrickF1 commented 2 years ago

Haven't tried out your code yet but there's already been two PRs for this that I didn't accept (yet) because I want something very specific for it. https://github.com/PatrickF1/fzf.fish/pull/138

I want the preview to show both the staged and non-staged changes.

NextAlone commented 2 years ago

Haven't tried out your code yet but there's already been two PRs for this that I didn't accept (yet) because I want something very specific for it. #138

I want the preview to show both the staged and non-staged changes.

Just noticed that there were PRs here.

PatrickF1 commented 2 years ago

Don't let the fact the other two PRs didn't get merged discourage you. It was more because the authors lost interest than this feature being impossible to work on (I hope). If you can make the preview show both the staged and working directory diffs against HEAD, then I am happy to merge. Two potential solutions:

NextAlone commented 2 years ago

Don't let the fact the other two PRs didn't get merged discourage you. It was more because the authors lost interest than this feature being impossible to work on (I hope). If you can make the preview show both the staged and working directory diffs against HEAD, then I am happy to merge. Two potential solutions:

Ok, i will check these two.

NextAlone commented 2 years ago

Don't let the fact the other two PRs didn't get merged discourage you. It was more because the authors lost interest than this feature being impossible to work on (I hope). If you can make the preview show both the staged and working directory diffs against HEAD, then I am happy to merge. Two potential solutions:

Are you talking about being displayed together or separately?

NextAlone commented 2 years ago

How about this?

It preview untracked files/dirs as ordinary files/dirs, and diff new file with /dev/null, the others diff with HEAD.

if string match -r '\?\?' {1} > /dev/null
    _fzf_preview_file {2..}
else if string match -r 'A' {1} > /dev/null
    git diff --color=always -- /dev/null {2..}
else
    git diff --color=always HEAD -- {2..}
end

Or split cached and uncached changes.

...
else 
    echo 'Unstaged'
    git diff --color=always HEAD -- {2..}
    echo -e '\nStaged'
    git diff --color=always --cached HEAD -- {2..}
end
PatrickF1 commented 2 years ago

Are you talking about being displayed together or separately?

If there are both staged and working tree changes, I want the preview to show both.

Yeah the second one is along the lines of what I'm thinking. I guess you don't need the intermediate file to store them huh?

NextAlone commented 2 years ago

Are you talking about being displayed together or separately?

If there are both staged and working tree changes, I want the preview to show both.

Yeah the second one is along the lines of what I'm thinking. I guess you don't need the intermediate file to store them huh?

Yes, no intermediate file, and add check with status (just simply string match, don't know other convenient way)?

if string match -r '\?\?' {1} > /dev/null
    _fzf_preview_file {2..}
else if string match -r 'A' {1} > /dev/null
    git diff --color=always -- /dev/null {2..}
else 
    if string match -r '\S\s\S' > /dev/null
        echo -e (set_color red)Unstaged
        echo
        git diff --color=always HEAD -- {2..}
        echo
    end
    if string match -r '\s\s|\S\S\s' > /dev/null
        echo (set_color green)Staged
        echo
        git diff --color=always --cached HEAD -- {2..}
    end
end

image

NextAlone commented 2 years ago
 X          Y     Meaning
 -------------------------------------------------
          [AMD]   not updated
 M        [ MTD]  updated in index
 T        [ MTD]  type changed in index
 A        [ MTD]  added to index
 D                deleted from index
 R        [ MTD]  renamed in index
 C        [ MTD]  copied in index
 [MTARC]          index and work tree matches
 [ MTARC]    M    work tree changed since index
 [ MTARC]    T    type changed in work tree since index
 [ MTARC]    D    deleted in work tree
             R    renamed in work tree
             C    copied in work tree
 -------------------------------------------------
 D           D    unmerged, both deleted
 A           U    unmerged, added by us
 U           D    unmerged, deleted by them
 U           A    unmerged, added by them
 D           U    unmerged, deleted by us
 A           A    unmerged, both added
 U           U    unmerged, both modified
 -------------------------------------------------
 ?           ?    untracked
 !           !    ignored
 -------------------------------------------------

Not works with R(renamed), C(copied), T(type changed), and unmerged status. i will find out the way.

NextAlone commented 2 years ago

Are you talking about being displayed together or separately?

If there are both staged and working tree changes, I want the preview to show both. Yeah the second one is along the lines of what I'm thinking. I guess you don't need the intermediate file to store them huh?

Yes, no intermediate file, and add check with status (just simply string match, don't know other convenient way)?

if string match -r '\?\?' {1} > /dev/null
    _fzf_preview_file {2..}
else if string match -r 'A' {1} > /dev/null
    git diff --color=always -- /dev/null {2..}
else 
    if string match -r '\S\s\S' > /dev/null
        echo -e (set_color red)Unstaged
        echo
        git diff --color=always HEAD -- {2..}
        echo
    end
    if string match -r '\s\s|\S\S\s' > /dev/null
        echo (set_color green)Staged
        echo
        git diff --color=always --cached HEAD -- {2..}
    end
end

image

maybe this is enough to preview

NextAlone commented 2 years ago

No need to split ^A, it works with staged file

PatrickF1 commented 2 years ago

Thanks for the updates. This week is really busy so it'll be a while before I can come back to review but just letting you know I won't forget about this

NextAlone commented 2 years ago

Thanks for the updates. This week is really busy so it'll be a while before I can come back to review but just letting you know I won't forget about this

It doesn't matter, I will always be here.

NextAlone commented 2 years ago

Thanks for the updates. This week is really busy so it'll be a while before I can come back to review but just letting you know I won't forget about this

It doesn't matter, I will always be here.

PatrickF1 commented 2 years ago

Don't worry I haven't forgotten about this, just thinking through what is the best way to make this feature simple and easy to use!

NextAlone commented 2 years ago

And if there any other changes request?

PatrickF1 commented 2 years ago

Nope, I'll take it from here and merge soon :)

PatrickF1 commented 2 years ago

Thanks for working on this and especially our patience @NextAlone! Really appreciate it. You are the third person to try to PR this change in and it seems third time's the charm. Sorry I've been so busy.

NextAlone commented 2 years ago

Thanks for working on this and especially our patience @NextAlone! Really appreciate it. You are the third person to try to PR this change in and it seems third time's the charm. Sorry I've been so busy.

Also thanks for your work, this is such a wonderful plugin.

NextAlone commented 2 years ago

Thanks for working on this and especially our patience @NextAlone! Really appreciate it. You are the third person to try to PR this change in and it seems third time's the charm. Sorry I've been so busy.

Also thanks for your work, this is such a wonderful plugin.

davidnanry commented 2 years ago

Thank you both! This is an excellent addition to an excellent plugin

NextAlone commented 2 years ago

@PatrickF1 And it is time to update Modified paths section in Readme.

PatrickF1 commented 2 years ago

I did update it. I'll add a gif later. Or did you mean something else?

NextAlone commented 2 years ago

I did update it. I'll add a gif later. Or did you mean something else?

Just the gif,thanks for your work.