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 tmux session name to be passed as env var #1703

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alerque
Copy link

@alerque alerque commented Apr 4, 2019

Note this is a replacement for the obsolete PR #952.

I finally got this actually figured out and rebased on master. The priority is now:

  1. A manual environment variable (great for keyboard shortcut launches, remote ssh connections, etc.)
  2. The value of the zstyle setting
  3. A default string of "prezto"

For normal usage this change should be a NOOP. However it enables the
use case where the user might want to predefine what session gets
connected to when the shell is launched. Running zsh will still net
you a connection to the last used tmux session or a new one named
"zprezto" if none exists. However env tmux_session=myname zsh will
connect you specifically to a session called 'myname' including creating
it if it doesn't exist.

This is particularly useful in window managers where a key binding might
open a terminal with a predefined session or even show a list of current
sessions and open a new terminal connected to that session.

The default session name may still be set using zstyle as documented.

@jeffwidman
Copy link
Collaborator

👍 on the general idea here.

I had a hard time stepping through the code... have you tested all these scenarios?

Also, your PR has a great explanation... maybe copy some of that to the tmux module readme?

@alerque
Copy link
Author

alerque commented May 24, 2019

Yes I've tested all the scenarios mentioned. I've been using this since 2015 and use all four scenarios on a daily basis. I had to re-code the logic a little bit to keep up with prezto changes, but the basic idea is the same. The code isn't that complicated to step through:

  1. If the var (trimmed) is empty, then try to set it from zstyle. If it's still empty set it to the default string.
  2. Use the var.
  3. Explicitly use the var rather than letting tmux guess in case the requested session isn't the default.

I'm on the road right now but will try to add docs at some point.

@jeffwidman
Copy link
Collaborator

nudge re: adding docs as previously discussed

For normal usage this change should be a NOOP. However it enables the
use case where the user might want to predefine what session gets
connected to when the shell is launched. Running `zsh` will still net
you a connection to the last used tmux session or a new one named
"zprezto" if none exists. However `env tmux_session=myname zsh` will
connect you specifically to a session called 'myname' including creating
it if it doesn't exist.

This is particularly useful in window managers where a key binding might
open a terminal with a predefined session or even show a list of current
sessions and open a new terminal connected to that session.

The default session name may still be set using zstyle as documented.
@alerque
Copy link
Author

alerque commented Jun 20, 2019

Thanks @jeffwidman, you caught me at a computer this time (since the issues isn't assigned to me it wasn't really staying on my radar!). I've added some documentation to the README and stuffed it in the same commit.

@jeffwidman
Copy link
Collaborator

Thank you!

So stepping through this, I'm a little confused. You said:

For normal usage this change should be a NOOP... Running zsh will still net
you a connection to the last used tmux session or a new one named
"zprezto" if none exists.

However, reading the code and the comments, it looks like the fallback behavior does change from the last session session used to instead using the "prezto" session name.

If someone doesn't set this var, and last used a different session name, will this change the behavior for them to instead start attaching to the "prezto" name?

I don't have an opinion yet whether that is a good or bad thing--it might be an improvement it might not, but I first want to make sure I understand how this works.

@alerque
Copy link
Author

alerque commented Jun 21, 2019

@jeffwidman Thanks for your patience. My logic did in fact slip a cog somewhere, this needs to be a 4 stage fallback not a 3 stage fallback.

  1. env variable
  2. last used
  3. user set zstyle default
  4. hard coded 'prezto' default

Да?

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