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

Show and switch to a window instead of a session #12

Merged
merged 6 commits into from
Jun 16, 2024

Conversation

RensOliemans
Copy link
Contributor

The format shown to the user is slightly modified, see here the difference:

Before:

dotfiles: 2 window(s) (attached)
thesis: 1 window(s)
/home/user/Downloads
...

After:

dotfiles/zsh (attached)
dotfiles/tmux
thesis/toolset
/home/user/Downloads
...

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 with C:\?), 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 the session_name contains a space (and another session_name exists with the first word as beginning as well).

@RensOliemans
Copy link
Contributor Author

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.

@RensOliemans
Copy link
Contributor Author

RensOliemans commented Feb 25, 2024

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.

@27medkamal
Copy link
Owner

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:

  1. Add a tmux setting to switch between the current behaviour and the new behaviour defaulting to the old behaviour.
  2. Maybe have a delimiter other than / to avoid the potential issues you mentioned, maybe ->?

Let me know if you can address the 2 points above. Thanks.

RensOliemans added a commit to RensOliemans/tmux-session-wizard that referenced this pull request Mar 23, 2024
@RensOliemans
Copy link
Contributor Author

1. Add a tmux setting to switch between the current behaviour and the new behaviour defaulting to the old behaviour.

Done in 1c235b9, 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 09ff236. 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!

@RensOliemans
Copy link
Contributor Author

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.

@RensOliemans RensOliemans marked this pull request as draft April 16, 2024 19:58
@RensOliemans
Copy link
Contributor Author

RensOliemans commented Apr 16, 2024

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.

@27medkamal
Copy link
Owner

No worries. Also, please note that there's a big refactor coming up as part of #9 so you might want to keep that in mind to avoid conflicts

@RensOliemans
Copy link
Contributor Author

RensOliemans commented Apr 17, 2024 via email

@RensOliemans RensOliemans marked this pull request as ready for review May 7, 2024 14:39
@RensOliemans
Copy link
Contributor Author

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.

The default output is still

    conf-dot: 2 window(s)
    ~/.tmux/plugins/tmux-session-wizard
    ~/email
    ~/Projects
    ~/Documents/thesis

But with the option "@session-wizard-windows on", the output becomes

    conf-dot: zsh(1)
    conf-dot: tmux(2)
    ~/.tmux/plugins/tmux-session-wizard
    ~/email
    ~/Projects

`tmux select-window` allows a window to be specified with either an
index or a name, and we take the index, which is selected by

    awk -F"[()]" '{print $(NF-1)}'
@mandos
Copy link
Contributor

mandos commented May 19, 2024

@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
Copy link
Contributor Author

RensOliemans commented May 19, 2024 via email

@mandos
Copy link
Contributor

mandos commented May 19, 2024

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 (/ 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).

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.

@RensOliemans
Copy link
Contributor Author

RensOliemans commented May 19, 2024 via email

@27medkamal 27medkamal merged commit 4b04113 into 27medkamal:main Jun 16, 2024
@27medkamal
Copy link
Owner

I'm happy to include this. I'm sure some people would find it useful.

@RensOliemans
Copy link
Contributor Author

RensOliemans commented Jun 17, 2024 via email

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.

None yet

3 participants