-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for fzf as a frontend UI #307
Conversation
This adds fzf support by: 1. Make a command `mcfly fzf` which just prints the command history as text to stdout 2. Modify the binding code in the shell init scripts so that if `MCFLY_FZF` is defined then Ctrl+R will instead run a copy of fzf reading its input from the `mcfly fzf` command The only limitations of note are: 1. The MCFLY_FZF variable is only evaluated at init time. Due to the way that bash Ctrl+R is handled, it's not clear how to make the Ctrl+R binding change if the user sets MCFLY_FZF after init 2. Deletion is not supported within the fzf interface, though running `mcfly search` manually should work fine
One additional limitation I have since thought of:
I will try implementing this over the weekend, which will require making the functionality of the History In general, I'd be happy to take input on whether this change is desirable for mcfly, and if so how to make it minimally invasive on the rest of the code base. |
Hey @bnprks, I'm trying to decide if this feels like a good direction for mcfly. It feels like it adds unneeded complexity. Does |
- Split `mcfly fzf` command into two subcommands: `mcfly fzf show` to print history entries as input to fzf, and `mcfly fzf select` to mark a command as selected from the fzf interface - In the shell Ctrl+R keybindings for MCFLY_FZF, mark the selected command via `mcfly fzf select`
Yes, Of course an external command would be able to similarly read the mcfly database without modifying the core mcfly code. In this case, I think two aspects mean the wrapper code will have to contain a large fraction of mcfly logic internally:
It would probably be feasible to implement this using mcfly as a dependency in order to pull in this mcfly logic rather than being part of the core mcfly binary. |
Okay, I think I understand better now. So you want to add a mcfly command that prints the sorted, prioritized DB view to STDOUT. That's reasonable. I think you could do that (perhaps call it |
Yeah, I think you're understanding the goals right. Thinking about it more, it might be possible to split entirely into a new repo. I'll test it out before completely abandoning this pull request, but I think since mcfly is on crates.io it might work to have a I think the main question there would be whether mcfly's public API exposes all the needed functionality, but I think it does |
I think you might need to expand the exposed API or add |
@cantino is it currently possible to pipe results between mcfly and fzf? Use mcfly as the search "backend" while fzf handles the UI. |
@danihodovic, It isn't possible today, but with the new options to |
My first tests on separating this into a new binary seem promising -- basically all rust functions called in The only change that would be needed in the main |
@bnprks Do you think it would be best to add the mcfly search command to dump text so that you're not depending on an internal API? |
Please take https://github.com/lotabout/skim into consideration as well, so it's not completely tied into |
I assume skim would be able to handle dumping text from |
I've had success making a companion tool to mcfly here: https://github.com/bnprks/mcfly-fzf I think compatibility with mcfly should be fairly straightforward to maintain even if the mcfly rust API changes. The only point of direct interaction between the I think it is most logical to have a companion tool specialized to providing the fzf interface. Being able to specialize the output and functionality to fzf's CLI options has been quite valuable and I'm not sure a generic text-dump option in mcfly would be able to provide as good a user experience without becoming tied to assumptions about how fzf works specifically. Of course I'd be happy to help port some changes into the main mcfly binary if desired, but the companion-tool approach might scale better if people want to add support for other fuzzy search CLIs in the future. |
Nice work @bnprks! |
EDIT: I think now that a companion tool is a better approach for this, so I've closed the pull request and made mcfly-fzf
This pull request adds an option to use fzf as the front-end UI, addressing issue #158
If the environment variable
MCFLY_FZF
is defined at init time, then the fzf UI will be bound to Ctrl+R rather than the mcfly interfaceThis adds fzf support by:
mcfly fzf
which just prints the command history as text to stdoutMCFLY_FZF
is defined then Ctrl+R will instead run a copy of fzf reading its input from themcfly fzf
command with reasonable UI defaultsThe only limitations of note are:
mcfly search
manually should work fine