omerxx / tmux-sessionx

A Tmux session manager, with preview, fuzzy finding, and MORE
GNU General Public License v3.0
554 stars 51 forks source link

Feature: ability to add on the fly key to few selected sessions/windows, to switch to them faster. #92

Closed swaroopanand10 closed 1 month ago

swaroopanand10 commented 1 month ago

When we are working with multiple sessions and windows, then switching between them is sometimes slow and repetitive through fzf. It would be great if there was a way to navigate in a harpoon way.

In neovim there is great plugin which does that for buffers- https://github.com/otavioschwanck/arrow.nvim

In this plugin, If we want to switch between some selected buffers, we just have to press one leader key like ';' and then bookmark window will open, then we can press the key assigned to respective buffer we want to switch and we will be taken to that buffer. This approach only take two keystrokes to switch to desired buffer. It also has features of adding and removing the buffers from bookmarks.

Can something like that plugin also be implemented in tmux? In which we can add some desired windows/sessions to our bookmark list with a key assigned to that window. and then we can open that bookmark list through a leader key. After that we can press the key respective to a particular window/session and we can switch to it.

I don't know if this feature is possible to implement in tmux or not, But I am still curious and opening this issue in case if it is possible. Thank you for this great plugin.

omerxx commented 1 month ago

@swaroopanand10 Interesting thanks for bringing this here. So with regards to windows I think it would duplicate and existing functionality (prefix + window number), BUT sessions can be a great options. I still need to think whether this belongs here or a plugin of it's own (tmux-arrow?? :) )

Assuming this was a standalone plugin, how do you think of the UX? Maybe something like -

BTW - this can be integrated here, if the hotkey opens up sessionx focused on the target plugin and you hitting enter to approve.

Thoughts?

swaroopanand10 commented 1 month ago

@omerxx Thanks for considering this,

prefix + session hot key => attaches to the session

I think this could lead to keybind collision, as a lot of tmux shortcuts and plugin's keybinds already have their keys in form of -> prefix + some key.

prefix + general plugin key => show a menu / popup with existing sessions and their hotkey (auto assigned by the plugin?)

I think this could be correct, BUT auto assignment of hot keys to all sessions could be avoided, as there are a lot of sessions that we don't visit very often. So assigning keys to them would not be optimal. So, there should be a list of custom selected sessions (with options to customize that list like add and remove from that list), and hotkeys should be assigned only to those selected sessions.

Also it would be great if we could also customize the hotkeys themselves with some option like - index_keys = 'asdfghjklrzxcni123456789uo' (this option is present in arrow.nvim) And the hotkeys will be assigned according to this priority(a to first selected session, s to second selected session etc.) And also we should be able to change the order of sessions according to their priority.

Now, in case of windows vs sessions, I am not sure, but it would be great if there would be an option in which we can choose whether we want to assign a hotkey to an window(from all the existing sessions) like session3:window4, or to just a session.

Sorry but I have no experience in plugin development so I cannot say if there should be a separate plugin or not, that is why it would be correct for you to decide on that.

omerxx commented 1 month ago

@swaroopanand10 Here's what I'm thinking and tell me if this suits the requirement -

  1. You'll hit a new prefix for sessionx that will launch it with key bindings in the list (e.g. mysession [b]
  2. Hitting the key alone will immediately put you in the session

(1) can also be a mode within sessionx turned with an internal binding like other in-plugin modes.

Having all of the above said, would it be very different then a fuzzy picker? I mean, you still have to pop a plugin and hit a keystroke, using the current plugin this is roughly the same - you pop it, 99% chance all you have to hit is the first letter of your session's name and enter. I'm assuming the extra keystroke (enter) is the difference (which I get).

To fix this, we can add a flag to fzf to automatically select the session if it's the only one in the list, so if there's only one starting with b for example, just hitting b would take you there, obviously the more similarity between names the more typing.

This can also be mitigated by assigning random prefixes, HOWEVER, I think keeping real names is best of both worlds, and statistically speaking, the smartest...

Sorry for the long reply :) Thoughts?

omerxx commented 1 month ago

@swaroopanand10 Please see the proposed change, you can try it by changing your TPM plugin to

omerxx/tmux-sessionx#92-auto-selection

And updating

swaroopanand10 commented 1 month ago

Yes I tried it and I think it is very good and practical way, It works nicely. Thanks for your help.

omerxx commented 1 month ago

Merged #94