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

refactor main.sh #82

Merged
merged 1 commit into from
Apr 7, 2024
Merged

refactor main.sh #82

merged 1 commit into from
Apr 7, 2024

Conversation

isidroas
Copy link
Contributor

  • fix copy-mode removal when not in copy mode
  • earlier conversion from pipes to newlines
  • reduced and more clear code

@sainnhe
Copy link
Owner

sainnhe commented Apr 1, 2024

Sorry for late reply. I was just too busy recently (maybe you've heard of 996 in China) and I just had a little time to deal with this :(

# remove copy-mode from options if we aren't in copy-mode
if [[ "$TMUX_FZF_ORDER" == *"copy-mode"* ]] && [ "$(tmux display-message -p '#{pane_in_mode}')" -eq 0 ]; then
Copy link
Owner

Choose a reason for hiding this comment

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

So the code assumes $TMUX_FZF_ORDER is exactly "copy-mode|session|window|pane|command|keybinding|clipboard|process", but in fact users can customize $TMUX_FZF_ORDER, as described in README. That's why there is a detection:

[[ -z "$TMUX_FZF_ORDER" ]] && TMUX_FZF_ORDER="copy-mode|session|window|pane|command|keybinding|clipboard|process"

The if condition [ "$TMUX_FZF_ORDER" == *"copy-mode"* ] is used to detect if there is a substring "copy-mode" in $TMUX_FZF_ORDER, so it should not be removed, although the functionality didn't change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it because it makes the code simpler and the functionality didn't change. With this pr, if the substring copy-mode isn't present in $TMUX_FZF_ORDR sed won't remove anything

if [[ "$TMUX_FZF_ORDER" == *"copy-mode"* ]] && [ "$(tmux display-message -p '#{pane_in_mode}')" -eq 0 ]; then
TMUX_FZF_ORDER="$(echo $TMUX_FZF_ORDER | sed -E 's/\|?copy-mode\|?//')"
if [ "$(tmux display-message -p '#{pane_in_mode}')" -eq 0 ]; then
items_origin="$(echo "${items}" | sed '/copy-mode/d')"
Copy link
Owner

Choose a reason for hiding this comment

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

IMO the functionality didn't change here. Doesn't sed -E 's/\|?copy-mode\|?//' work on your machine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the default value of TMUX_FZF_ORDER , it works fine:

$ echo "copy-mode|session|window|pane|command|keybinding|clipboard|process" | sed -E 's/\|?copy-mode\|?//'
session|window|pane|command|keybinding|clipboard|process

but swapping copy-mode and session,

$ echo "session|copy-mode|window|pane|command|keybinding|clipboard|process" | sed -E 's/\|?copy-mode\|?//'
sessionwindow|pane|command|keybinding|clipboard|process

produces that session and window items are merged without the pipe separator.

The change proposed in #66 fixes it:

$ echo "session|copy-mode|window|pane|command|keybinding|clipboard|process" | sed -E 's/\|?copy-mode\|?/|/'
session|window|pane|command|keybinding|clipboard|process

but as you noticed, the first line could become empty since it could add a leading pipe character

$ echo "copy-mode|session|window|pane|command|keybinding|clipboard|process" | sed -E 's/\|?copy-mode\|?/|/'
|session|window|pane|command|keybinding|clipboard|process

@isidroas
Copy link
Contributor Author

isidroas commented Apr 6, 2024

Hi @sainnhe good to see some activity is this project!

I didn't know about 996, it sounds awful 😞

@sainnhe
Copy link
Owner

sainnhe commented Apr 7, 2024

LGTM. Thank you so much for this refactor!

@sainnhe sainnhe merged commit 0e02006 into sainnhe:master Apr 7, 2024
@sainnhe
Copy link
Owner

sainnhe commented Apr 7, 2024

After some tests I found a bug: the items will not show in copy mode. I did a quick fix: 608356a

The cause is simple: if you enter copy mode, line 10~12 will be skipped, so the variable items_origin will not be defined until line 17, thus the TMUX_FZF_ORDER variable will be completely unused.

@isidroas
Copy link
Contributor Author

isidroas commented Apr 8, 2024

Thank you for letting me know. Next time I will test more before submitting the pull request.

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

Successfully merging this pull request may close these issues.

2 participants