gfold icon indicating copy to clipboard operation
gfold copied to clipboard

feature request: integrate with fzf & jump to dir

Open Dentrax opened this issue 2 years ago • 9 comments

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?

Dentrax avatar Jan 12 '22 12:01 Dentrax

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.

nickgerace avatar Jan 13 '22 17:01 nickgerace

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?

Dentrax avatar Jan 14 '22 18:01 Dentrax

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 :)

nickgerace avatar Jan 14 '22 19:01 nickgerace

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.

mriehl avatar Mar 01 '22 07:03 mriehl

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.

nickgerace avatar Mar 01 '22 18:03 nickgerace

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:

  • $dir being the directory you want to search.
  • awk 'NR%4==1 will skip to the write rows of output from gfold to grab the project directory. (line number modulo 4 is equal to 1)
  • I've completely forgotten why the sed line was necessary
  • the fzf command is just formatting

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.

BerkeleyTrue avatar May 12 '22 02:05 BerkeleyTrue

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.

nickgerace avatar May 12 '22 19:05 nickgerace

@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.

BerkeleyTrue avatar May 13 '22 21:05 BerkeleyTrue

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 avatar May 16 '22 15:05 nickgerace