junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
65.33k stars 2.4k forks source link

Kill command completion doesn't complete signal names #1139

Open barlik opened 6 years ago

barlik commented 6 years ago

I have standard bash completions installed (https://github.com/scop/bash-completion) and it includes a way to complete signal names for kill command by running:

kill -s <tab> -> a list of signals
kill -<tab> -> a list of signals

After adding fzf completions, this no longer works. Kill command completion from FZF package only completes PIDs and it doesn't fall-back to previously defined completion.

junegunn commented 6 years ago

I see, do you know how to fix it?

barlik commented 6 years ago

Yes, I can. However, I've been looking into fzf completions yesterday and thinking about a different approach for it.

FZF completions are currently duplicating some code that's already defined inside bash completions. For example, in fzf when you expand '**' it triggers a fzf defined shell function to prepare a list of hosts to complete. This function is however not identical to the the bash's one. E.g. in bash I use HOSTFILE to add additional hosts for the host completion. This is missing from the fzf '**' completion. The situation is the same with other commands (e.g. kill command doesn't complete signals).

I think that an alternative way to approach completions might be to leverage the existing completions and use fzf to filter those. It would work like this:

ssh -i ** -> completion of files with fzf
ssh -l ** -> completion of users with fzf 
ssh -c ** -> completion of crypto algorithms with fzf

By leveraging the existing completions you can:

  1. fix inconsistencies between the completions.
  2. remove a lot of code from fzf completions and make it simpler though more powerful.
  3. remove the need to specify which commands need file completion and which need directory completion. This is handled by bash completions already.
  4. by changing the trigger to <tab> you can have fzf be applied to all completions. This is quite amazing.

I've tried that with a proof of concept ssh completion and it works great. The code is in the early stage, it's just a proof of concept as of now. It triggers the existing completion and then it uses fzf to select the item from the completion list. Hopefully, I'll find a bit more time to finish it in the next couple of days. It might work as a replacement or an alternative to the current completions.

junegunn commented 6 years ago

Cool, love the idea!

that's already defined inside bash completions

Only if you installed custom bash completions such as the one you linked above. We can leverage those external completions, but we still have to use our functions when alternatives are not found.

peterfpeterson commented 2 years ago

I would love to use the bash-native list of hosts for completion through fzf. Any chance you still have your proof of concept to share? It looks like #1149 might be it.