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

Allow attaching without providing session name when multiple sessions exist #2100

Open
zolrath opened this issue Jan 16, 2023 · 12 comments
Open

Comments

@zolrath
Copy link

zolrath commented Jan 16, 2023

Currently if you run zellij attach with a single session, it will successfully attach, but if there are multiple sessions active the command will fail and list the sessions instead.

My initial expectation is that it would attach to the session I most recently exited, allowing me to hop in and out of a session easily but still swap to other sessions at will.

I'd expect this to be the default but it could be added as an --recent option or something of that nature if needed.

@thisismygitrepo
Copy link

thisismygitrepo commented Jan 17, 2023

A solution exists already. In integrations you can see a snippest that uses fzf to choose your session. With this intergration, you will be literally one keystroke away from entering your session, which is definitely faster than your proposed --recent 8 keystrokes flag solution. You can customize it further to your taste and default behaviour expectations.

@zolrath
Copy link
Author

zolrath commented Jan 17, 2023

Those are great for user facing commands but if I set a my shell to auto start zellij, also from integrations with

set ZELLIJ_AUTO_ATTACH true
set ZELLIJ_AUTO_EXIT true
eval (zellij setup --generate-auto-start fish | string collect)

my terminal will fail to launch if I have more than one zellij session active as the attach command fails.

@thisismygitrepo
Copy link

Yes I see.

  • Once again, if you insist on using this integration in particular, then one must attend to your request about how default behaviour should be.

  • But if you are looking for a quick solution, I think you can call the other integration that I mentioned, and remove the fzf from it, and write simple if statement to implement your logic of defaulting to most recent session if sessions exist. The modified script sould be sourced or included explicitly in your .bashrc.

  • An even quicker solution it to put this one-liner zellij attach default_sess_name -c, which creates it if not available and attach if available, but it differ from your request in that it specifies the name.

@thisismygitrepo
Copy link

thisismygitrepo commented Jan 17, 2023

BTW, the integrations that you mentioned have different behaviour from your issue discription. The auto-start integration keeps creating new sessions whenever I login (I use bashrc). My pick with it is that it creates too many sessions and at some point your need to start filter through them one by one to see which one to close. This is probably the diametrical opposite of your problem of not attaching.

@zolrath
Copy link
Author

zolrath commented Jan 17, 2023

I'm simply using the auto-attach code that zellij produces for fish, and it fails once you have two sessions. I'm not looking for a quick solution, I'm fine creating my own logic for now but in the long run this shouldn't be able to case your terminal to fail to launch.

With a single session, every new terminal successfully reattaches to the session, as expected.

If I open a second session:

❯ zellij list-sessions
tested-fang (current)
stiff-fall

all new terminals fail immediately.

[process exited with code 15 (0x0000000f)]

The bash script may function differently, if that's the case the bug report here would be that the fish script handles multiple sessions incorrectly, as this setting should not stop your terminal from launching.

@raphCode
Copy link
Contributor

Are you aware that there are shortcuts to attaching a particular session? Example:

$ zellij a
Please specify the session to attach to, either by using the full name or a unique prefix.
The following sessions are active:
better-laborer
mammoth-disease
$ zellij a b # attaches the first session

Also, you can set a custom, fixed session name and use that as your "main" session to attach to by default.

@sascha-wi
Copy link

Also, you can set a custom, fixed session name and use that as your "main" session to attach to by default.

Where would I do that?

@zeratax
Copy link

zeratax commented Nov 10, 2023

yeah imo the shell integrations are broken currently. the script generated by zellij setup --generate-auto-start bash should probably also include a default session name.

@noahbald
Copy link

An even quicker solution it to put this one-liner zellij attach default_sess_name -c, which creates it if not available and attach if available, but it differ from your request in that it specifies the name.

I'd also like something like this, where it will create a new session when the default is already in use

@noahbald
Copy link

noahbald commented Dec 31, 2023

I've cooked up the following launch command which might do what we want

zellij a main || zellij -s main || zellij

Which will attempt to attach to main, or create main, or otherwise launch normally

@rsniezek
Copy link

rsniezek commented Apr 3, 2024

Something like this would enable user to specify the session name without command chainging:
#3233

@mlambie
Copy link

mlambie commented May 28, 2024

I've cooked up the following launch command which might do what we want

zellij a main || zellij -s main || zellij

Which will attempt to attach to main, or create main, or otherwise launch normally

I have alias engage='zellij attach --create main' in my .zshrc for a similar purpose.

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

No branches or pull requests

8 participants