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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions modules/tmux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ You can change the default session name with:
zstyle ':prezto:module:tmux:session' name '<YOUR DEFAULT SESSION NAME>'
```

A session name may also be specified in an environment variable before ZSH runs.

```sh
env tmux_session='<SESSION NAME>' zsh
```

This can be useful for example to connect to a specific remote session
connecting via SSH (note that OpenSSH needs to be configured to pass on that
environment variable). It can also be used with window managers to set keybindings
that launch terminals with specific sessions.

With `auto-start` enabled, you may want to control how multiple sessions are
managed. The `destroy-unattached` option of tmux controls if the unattached
sessions must be kept alive, making sessions available for later use, configured
Expand Down
11 changes: 6 additions & 5 deletions modules/tmux/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && -z "$VSCOD
); then
tmux start-server

# Create a 'prezto' session if no session has been defined in tmux.conf.
if ! tmux has-session 2> /dev/null; then
zstyle -s ':prezto:module:tmux:session' name tmux_session || tmux_session='prezto'
# Make sure we have a session to connect to, either named via an environment
# variable, the default style as documented, or 'prezto' for last resort
[[ -z "${tmux_session:// }" ]] && zstyle -s ':prezto:module:tmux:session' name tmux_session || : ${tmux_session:=prezto}
if ! tmux has-session -t "$tmux_session" 2> /dev/null; then
tmux \
new-session -d -s "$tmux_session" \; \
set-option -t "$tmux_session" destroy-unattached off &> /dev/null
fi

# Attach to the 'prezto' session or to the last session used. (detach first)
exec tmux $_tmux_iterm_integration attach-session -d
# Attach to the session name requested in an environment variable or the default (detaching others)
exec tmux $_tmux_iterm_integration attach-session -t "$tmux_session" -d
fi

#
Expand Down