wfxr / forgit

:zzz: A utility tool powered by fzf for using git interactively.
MIT License
4.32k stars 136 forks source link

feat(completions): add completion for fish #344

Closed folliehiyuki closed 4 months ago

folliehiyuki commented 4 months ago

fish's builtin git completion automatically registers git-forgit completions as completions for forgit subcommand of git. Therefore this PR provides completions for both formats git-forgit and git forgit.

Simple subcommands get the completion list from __fish_git_* functions, while others requiring more than 1 __fish_git_* completion sources reuse the completion items from the corresponding git commands.

Check list

Description

Type of change

Test environment

cjappl commented 4 months ago

Hi @folliehiyuki!

Thanks so much for the contribution(s) 🎉

Could you please:

  1. Figure out why the ci is faililng
  2. Give me a few test cases I can run locally on my machine with explicit detail to ensure the feature is working?

I'm the main fish maintainer, so I want to be sure I understand the feature fully and do some QA before merging!

sandr01d commented 4 months ago

I ran into the same issue with the CI previously, but the issue went away by itself before I could do anything to fix it. For some reason the fish PPA fails to install

Cannot add PPA: 'ppa:~fish-shell/ubuntu/release-3'.
ERROR: '~fish-shell' user or team does not exist.
Error: Process completed with exit code 1.

I'm suspecting an issue with the fish PPA. This is not caused by the code changes, the CI fails before the actual checks.

Just ran the test locally on my machine and they appear to be fine again. Could not test macos though, because act does not support this.

folliehiyuki commented 4 months ago

Give me a few test cases I can run locally on my machine with explicit detail to ensure the feature is working?

Just use git-forgit and git forgit as you normally do (while spamming the <TAB> key)!

mkdir test-repo && cd test-repo
git init
touch file{1,2,3}

# See that the completion list includes all subcommands
git forgit <Tab>
git-forgit <Tab>

# Completion for `add`
git-forgit add <Tab><Tab>
git forgit add <Tab><Tab>
...

All the __fish_git_* functions are sourced from the completion file of git, so you need it in-place first. It comes by default in every fish-shell package.

cjappl commented 4 months ago

@folliehiyuki this is great! Working as you intended.

A couple questions:

  1. Do you have any thoughts on if this should live in it's own file, or these methods be run at the end of forgit.plugin.fish? I don't know the overhead or cost, but I think it would be nice for the fish completions to "just work" when someone sources forgit. I am completely new in the area of fish completions, so I'm interested in your past knowledge or gut feeling on this.
  2. I'm noticing these completions are now much nicer than the ones on the normal functions/aliases (glo <TAB is very sad in comparision ) if you're feeling up to it, after this gets submitted one of us should go clean up those completions as well! This is a great upgrade.

Let me know what you think on point 1. Depending on that we can submit.

folliehiyuki commented 4 months ago

On point 1, see https://fishshell.com/docs/current/completions.html#where-to-put-completions.

So, it's better to put the fish completion in a separated file. It works with just the git-forgit command inside $PATH (I actually use git-forgit this way without all the aliases). There is no need to source the fish plugin.

On point 2, as said above, I don't use the fish plugin personally, so it's hard to judge. My recommendation would be to use abbr instead of aliases, so, on the command line, pressing glo<Space> would actually result to git forgit log being displayed and we'll have nice completion (still with fewer key presses).

cjappl commented 4 months ago

Awesome. Makes sense to me. Thanks again for the contribution @folliehiyuki ! merging it now.

If you feel you have energy to tune up the completions in the non-git-plugin version, another contribution would be greatly appreciated, otherwise I'll check it out when I have time.

Cheers!