Closed RensOliemans closed 4 months ago
Thanks for creating tmux-session-wizard
, I really like it! I found myself using it to switch to a session and immediately switching to the correct window often, which is why I made this change.
I created a PR since others might do the same. Of course, feel free to ignore this change if you don't like it. If you wish, I could also make it configurable, or fix the 2 downsides - though that might lead to a slightly more complicated solution.
Additional thing: I use the word attached
to signify the currently active window. That differs from tmux' wording, which is active
. The problem with that is that many windows can be active at the same time, since a window in a non-attached session can still be considered active.
This is counter-intuitive, for me the only window with special status is the one that I am seeing right now. To fix many windows showing up as active, I included a second check (#{?window_active, ...}
) in the tmux list-windows
call, but I did keep the attached
word in the output, even though it's probably not correct. Let me know if you prefer something else.
Thanks for submitting this. It does look like something some people would find useful, so I'm happy to include it. However, in the spirit of keeping the current behaviour as it is for anyone using it, we would need to:
/
to avoid the potential issues you mentioned, maybe ->
?Let me know if you can address the 2 points above. Thanks.
1. Add a tmux setting to switch between the current behaviour and the new behaviour defaulting to the old behaviour.
Done in 1c235b918418de0124794fc11a40af7ead2c0911, named @session-wizard-windows
. You can do set -g @session-wizard-windows on
in .tmux.conf
to enable it. This change is also documented in the README.
2. Maybe have a delimiter other than `/` to avoid the potential issues you mentioned, maybe `->`?
Fixed in 09ff236a7d77635bf19c966fc3e8143c187ae582. I am now using the delimiter →
. This is a Unicode character (U+2192), and thus reduces the likelihood of a user encountering this bug - they would have to have that character in their session name. I am also fine with "properly" fixing this bug, but it would make the code a bit more complicated. Let me know if you prefer that!
Note that window-switching functionality only works when the script being called by tmux.
Switching to a specific window (in general, I believe) cannot be done via calling a script via a shell, since you first have to switch to the session and then, when you are in the new session, switch to the correct window.
When doing this via a bash script, it will not work, since you are not actually "in" the new session whilst halfway through the script. I hope this make sense 😅.
This led me to forgo adding the -w
flag (see 1c235b9#L12) to the README, since it's not fully functional via the script. When it is called with -w
anyway, it will switch to the session perfectly fine, but not to the window, and it will complain about that.
Is this acceptable? The alternative is to check whether we are being called from bash or tmux and only switch to the window in the latter case, so that the warning is not shown. I have no idea how to check for that, however.
I just noticed that this PR does not retain all functionality of the current program (calling the script from command-line does not work as expected) and I don't have the time to immediately fix this. I will update this later, I'll think about how to do it properly first.
No worries. Also, please note that there's a big refactor coming up as part of https://github.com/27medkamal/tmux-session-wizard/pull/9 so you might want to keep that in mind to avoid conflicts
Sounds good, I'll look out for that. Thanks for the heads-up.
I rebased from master after the #9 merge and updated this PR. It is ready to go, the new get_tmux_option
helper function simplifies the code a bit with respect to the previous iteration.
@RensOliemans Are you sure that mixed windows with sessions is a good idea? The windows switcher is already implemented in Tmux (<prefix>w
) so I would avoid extending session list with additional data, which will life of a fuzzy finder make harder.
If you want to have windows switcher with similar interface to session-wizard, I would create separate command with only windows names, but personally I would give chance built-in feature because switching to another window is only two key strokes and you have also preview.
Let me know what do you think about it.
@RensOliemans Are you sure that mixed windows with sessions is a good idea?
No! I just like it for myself and my specific workflow :) My workflow is approximately this:
I group my sessions per topic, and windows per task (so for example a "thesis" session, with the windows "latex", "program" and "git"). I often think "alright I need to commit this thesis-related thing", and use your session-switcher with something like thes git
to find the appropriate window.
I built this because I found myself using your session switcher and nearly always switching to the appropriate window immediately after. <prefix>w
is great (and the preview is cool), but it's too slow and inflexible for me. Slow since it uses 2 more keystrokes than your program (/
and Enter
to start and stop searching), and inflexible because it doesn't have fuzzy search (I frequently distinguish between a "thesis/git" window and a "work/git" one).
The windows switcher is already implemented in Tmux (
<prefix>w
) so I would avoid extending session list with additional data, which will life of a fuzzy finder make harder.
That's OK! I made this PR because I thought it might help you or others, but if it's too specific to my workflow, feel free to reject it - it's your project 👍👍
If you want to have windows switcher with similar interface to session-wizard, I would create separate command with only windows names, but personally I would give chance built-in feature because switching to another window is only two key strokes and you have also preview.
I kept the session names in there because that allows me to distinguish between windows with a prompt like thes git
. I can also hide it if you want. I recently discovered fzfs beautiful --with-nth
, which would easily allow this and still enable precise matching.
Let me know what do you think about it.
Do whatever you think is best. I figured that our workflows are probably different (I have only used the zoxide
path feature once), mine is indeed much more like a <prefix>w
with fuzzy search.
I'm not maintainer, @27medkamal is. I was just curious about your workflow and maybe plan to change a little your implementation.
Slow since it uses 2 more keystrokes than your program (
/
andEnter
to start and stop searching), and inflexible because it doesn't have fuzzy search (I frequently distinguish between a "thesis/git" window and a "work/git" one).
I didn't concern about using search function, just <prefix>w
and number, so looks like shorter version but you need to find window yourself and with a lot of windows, it can be annoying, so I see why you want to use fuzzy finder here.
I kept the session names in there because that allows me to distinguish between windows with a prompt like
thes git
. I can also hide it if you want. I recently discovered fzfs beautiful--with-nth
, which would easily allow this and still enable precise matching.
Having session name in search is good, but still I think this feature should be separate from main session switcher/creator, because what you want is just windows switcher with fuzzy finder. Let wait for @27medkamal.
I'm not maintainer, @27medkamal is. I was just curious about your workflow and maybe plan to change a little your implementation.
Ah my bad, I wasn't paying attention.
Having session name in search is good, but still I think this feature should be separate from main session switcher/creator, because what you want is just windows switcher with fuzzy finder. Let wait for @27medkamal.
Yep that's right, I just want a window switcher with fuzzy finder. I thought this project was closest to that and added my usecase to it.
I'm happy to include this. I'm sure some people would find it useful.
Awesome, thanks!
The format shown to the user is slightly modified, see here the difference:
Before:
After:
This means that
RESULT
is modified as well. There is no colon in there, which means that we have to check whether the string begins with a/
. If it does,RESULT
is a path. If not, it must be a session. This has two downsides:It might not work on Windows, since a path probably does not start with
/
on Windows. I do not know how Windows paths work (do they start with\\
, Or withC:\
?), and I cannot test it.If the
session_name
starts with/
, the check fails because we assume that it is a path instead. This last part I have let it slide, since the current script is also not really forgiving if thesession_name
contains a space (and anothersession_name
exists with the first word as beginning as well).