nickgerace / gfold

CLI tool to help keep track of your Git repositories, written in Rust
https://crates.io/crates/gfold
Apache License 2.0
308 stars 20 forks source link

feature request: integrate with fzf & jump to dir #168

Closed Dentrax closed 4 months ago

Dentrax commented 2 years ago

Thanks for such a great tool!


Currently, it's a bit hard to use without selective mode. I still want to use fzf git repo search and jumping to dir by pressing ENTER.

atuin would be a great benchmark for this feature.

Screen Shot 2022-01-12 at 15 13 13

What do you think?

nickgerace commented 2 years ago

Thank you! I want to make sure that I understand the request:

Are you saying that you would like to jump to a directory with the given list of results? Perhaps in a TUI mode?

Although the performance of finding git repos can be improved, I am unsure what fzf integration will provide here. We will already have the results for all the repositories by the time you want to "jump", so fzf might not help by that point.

That being said, I could see a minimal TUI integration where you highlight a result, click "ENTER" on your keyboard, and then your current working directory is changed to it.

Dentrax commented 2 years ago

Are you saying that you would like to jump to a directory with the given list of results?

Yes! I thought fzf would just enough to handle jumping or searching, but you mentioned "fzf might not help". So, how atuin handles this?

nickgerace commented 2 years ago

From what I understand, atuin uses fzf for its search. gfold has its own search. While fzf is amazing, I think the main request here is to be able to cd into a repository via TUI. fzf may or may not replace gfold's search in this scenario, but that'll be done when researching this feature request.

Thus, I think it may be best to focus on the request to add an interactive mode where you can jump to a directory in the results. Whether or not fzf is involved can would likely be decided during the research phase :)

mriehl commented 2 years ago

If you want to jump to dir you need to eval it on the shell side. We have it in fw (which you also could consider using :wink: ). The idea is heavily inspired by virtualenvwrapper with the workon command, of course.

nickgerace commented 2 years ago

If you want to jump to dir you need to eval it on the shell side. We have it in fw (which you also could consider using wink ). The idea is heavily inspired by virtualenvwrapper with the workon command, of course.

This is what I have found from preliminary research as well. I'm still evaluating if it makes sense for this project, but I believe there is likely a path forward that doesn't stray too far from the core design.

BerkeleyTrue commented 2 years ago

For those interested, I've integrated this project into a script that allows me to jump through projects while opening them in new Tmux sessions.

You can achieve the above requirements using some simple scripts. I know the issue is about direct integration into this cli but I figured this can get you there in the meantime.

  res=$(
    gfold $dir |
      awk 'NR%4==1' |
      sed 's/\x1b\[[0-9;]*m//g' |
      fzf --reverse --header="Select project" --prompt=">" || exit 0
  )

Notes:

It looks like this:

image

The output should be the directory you want to cd into (full path) plus the project name. You'll need to parse out that bit. You can do that with this line path_name=$(echo $res | awk -F ' ~ ' '{print $2}')

The full script can be found here (with focus on the relevant lines for this conversion: https://github.com/berkeleytrue/dotfiles/blob/master/.local/bin/ta#L154

Hope y'all find this useful.

nickgerace commented 2 years ago

Thank you @BerkeleyTrue for the workaround for now! It looks great. I wonder: would the new json output help with your script? It might be easier to parse.

BerkeleyTrue commented 2 years ago

@nickgerace Yes, that would make integrating this project into others scripts much easier.

I also just remembered what the sed command is for, it's to remove the color escape terms, which where causing issues downstream. Tt would be helpful to add a no color option as well.

nickgerace commented 2 years ago

You are in luck @BerkeleyTrue! There is a no color option. Here's both together:

gfold -d json -c never

And you can dump those options into a config file to override defaults...

gfold -d json -c never --dry-run > ~/.config/gfold.toml
nickgerace commented 4 months ago

I commented on #169 as well (link), but gfold has settled on being a non-interactive, one-time use tool.

However, @BerkeleyTrue if you are still using this tool in a similar capacity, I highly recommend trying it out with the json display output and the color output disabled. We can likely add a section in README.md or somewhere in the docs with your fzf integration steps.