Skip to content
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

feat: Use fzf-tmux if fzf options are set #304

Closed
wants to merge 11 commits into from

Conversation

dljsjr
Copy link

@dljsjr dljsjr commented May 5, 2023

Check list

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation

Description

Overview

The meat of this change is to inspect whether or not we are in a tmux pane, and if so, we check the FZF_TMUX and FZF_TMUX_OPTS variables. If those are set, we use fzf-tmux instead of fzf and we forward the appropriate options.

This resolves #303

Changes

  • Add a do_fzf function for abstracting fzf invocation based on shell state as outlined above

  • Only hardcode -0/--exit-0 for fzf, as it causes flicker w/ tmux popup

  • Replace all invocations of fzf with do_fzf

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

@dljsjr
Copy link
Author

dljsjr commented May 5, 2023

I can address the lint failures when I’m back on a keyboard.

@dljsjr
Copy link
Author

dljsjr commented May 6, 2023

Sent up a fixup commit to address the shellcheck lints, I'll squash it down before merge once approved :)

@cjappl
Copy link
Collaborator

cjappl commented May 6, 2023

Don't stress about squashing, we use "squash and merge"

I'll hopefully get to test out and review soon! I've never heard about tmux-fzf but it sounds cool.

Thanks for the contribution, we will be back to you with comments/approval etc when we can 😀

@dljsjr
Copy link
Author

dljsjr commented May 6, 2023

I've never heard about tmux-fzf but it sounds cool.

For a heavy tmux user that uses a lot of panes/splits, the pop-up mode is invaluable:

CleanShot 2023-05-06 at 12 21 21

Copy link
Collaborator

@carlfriedrich carlfriedrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dljsjr, thanks for your patch! I added some feedback to certain lines.

bin/git-forgit Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
bin/git-forgit Outdated Show resolved Hide resolved
@dljsjr dljsjr marked this pull request as draft May 7, 2023 18:22
@dljsjr dljsjr marked this pull request as ready for review May 7, 2023 21:38
bin/git-forgit Outdated Show resolved Hide resolved
bin/git-forgit Show resolved Hide resolved
@dljsjr dljsjr requested a review from carlfriedrich May 7, 2023 21:44
@dljsjr
Copy link
Author

dljsjr commented May 7, 2023

@carlfriedrich I made some adjustments:

  1. -0 defaults to enabled across the board and the behavior is now configurable via a FORGIT-prefixed variable, mentioned in the README. Example:
    CleanShot 2023-05-07 at 16 37 49
  2. Made the splitting and sharing of the regular options and the tmux options much more explicit
  3. Adjusted the README as requested

Copy link
Collaborator

@carlfriedrich carlfriedrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for your effort. Just two more small change requests from my side.

bin/git-forgit Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
bin/git-forgit Show resolved Hide resolved
bin/git-forgit Show resolved Hide resolved
@dljsjr
Copy link
Author

dljsjr commented May 9, 2023

@carlfriedrich changes made and branch is rebased on top of latest upstream master. Also reworded the first commit to reflect the refactors made during review.

dljsjr added 10 commits May 9, 2023 12:56
The meat of this change is to inspect whether or not we are
in a `tmux` pane, and if so, we check the `FZF_TMUX` and
`FZF_TMUX_OPTS` variables. If those are set, we use `fzf-tmux`
instead of `fzf` and we forward the appropriate options.

- Add a `do_fzf` function for abstracting fzf invocation based on
shell state as outlined above.

- Add a new variable, FORGIT_SHOW_FZF_ON_EMPTY_LIST, for controlling when `--exit-0`
is forwarded to `fzf`.

- Replace all invocations of `fzf` with `do_fzf`.
@carlfriedrich
Copy link
Collaborator

@dljsjr Great, looks good code-wise for me now. Thanks a lot for your contribution!

I Did not do any functional tests, though, since I do not use tmux.
@cjappl Do you want to do any more testing or review? Otherwise I will merge this shortly.

@cjappl
Copy link
Collaborator

cjappl commented May 11, 2023 via email

@cjappl
Copy link
Collaborator

cjappl commented May 11, 2023

So far most commands are working well! However ga comes up with this when executing with the new fzf tmux, in fish

Screen Shot 2023-05-11 at 11 06 56 AM

Steps to repro:

  1. Use fish
  2. Make a change to some file
  3. export FZF_TMUX=1
  4. ga

This does not happen without step 3 (turning on this new FZF_TMUX). I won't be able to fully dig in today to triage. Let me know if you have any "aha's" and I'm happy to test again @dljsjr

@dljsjr
Copy link
Author

dljsjr commented May 12, 2023

@cjappl Hmm, interesting. I didn't modify any of that code, and I don't use fish.

I could probably get it set up and do a bisect. I did rebase this change on top of the latest origin/master after my last round of revisions so it also could have pulled in a regression from upstream.

@dljsjr
Copy link
Author

dljsjr commented May 12, 2023

@cjappl do you have anything in your .tmux.conf that forces a specific shell type, such as the macos reattach to user namespace stuff for pasteboard cooperation?

I think what's going on here is that the spawned tmux pane is executing things in fish instead of bash but I'm not 100% sure why yet. It's definitely not a regression, just something that's unique to the tmux configuration, and I'm not 100% sure why just right now.

Update

This is an oddity with tmux. After digging in, it kinda makes sense:

Any new panes/windows/splits/popups started inside of a tmux session will use the same $SHELL environment that the server was started with. So even though we export SHELL in such a way to "force" things to be bash, because the tmux server was forked from a fish shell, all new attachments to that server will use the same shell. Even though git-forgit is running in a bash context, the commands that get forwarded to --preview will be running in the context of the shell where fzf is running. That's the source of the error above.

Proposed Solution

Use bash -c in the preview commands.

@dljsjr
Copy link
Author

dljsjr commented May 12, 2023

@cjappl I've made the proposed change only for ga on this branch for right now; let me know if that works.

@cjappl
Copy link
Collaborator

cjappl commented May 13, 2023

Unfortunately no dice, similar issue

Screen Shot 2023-05-13 at 12 47 45 PM

I think the best option I'd recommend is you install and test it on fish. Otherwise, I can do the work on fish at some point in the future but it may take a bit for me to get to it!

Copy link
Collaborator

@cjappl cjappl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking merge for now until fish issues resolved

@dljsjr
Copy link
Author

dljsjr commented May 15, 2023

@cjappl Guess this is my excuse to give fish a try for the first time in like, 8 years :)

@cjappl
Copy link
Collaborator

cjappl commented May 15, 2023 via email

Copy link

stale bot commented Dec 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 15, 2023
@stale stale bot closed this Mar 17, 2024
@carlfriedrich
Copy link
Collaborator

@dljsjr Shall we reopen this? What are the chances that you'll get back to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

forgit does not open in a tmux popup window if fzf tmux options are set
3 participants