mirror of
https://github.com/sorin-ionescu/prezto.git
synced 2025-01-23 07:52:15 +08:00
Allow tmux session name to be passed as env var
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.
This commit is contained in:
parent
1f4601e44c
commit
c3f1794510
@ -33,6 +33,17 @@ You can change the default session name with:
|
|||||||
zstyle ':prezto:module:tmux:session' name '<YOUR DEFAULT SESSION NAME>'
|
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
|
With `auto-start` enabled, you may want to control how multiple sessions are
|
||||||
managed. The `destroy-unattached` option of tmux controls if the unattached
|
managed. The `destroy-unattached` option of tmux controls if the unattached
|
||||||
sessions must be kept alive, making sessions available for later use, configured
|
sessions must be kept alive, making sessions available for later use, configured
|
||||||
|
@ -29,16 +29,17 @@ if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && -z "$VSCOD
|
|||||||
); then
|
); then
|
||||||
tmux start-server
|
tmux start-server
|
||||||
|
|
||||||
# Create a 'prezto' session if no session has been defined in tmux.conf.
|
# Make sure we have a session to connect to, either named via an environment
|
||||||
if ! tmux has-session 2> /dev/null; then
|
# variable, the default style as documented, or 'prezto' for last resort
|
||||||
zstyle -s ':prezto:module:tmux:session' name tmux_session || tmux_session='prezto'
|
[[ -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 \
|
tmux \
|
||||||
new-session -d -s "$tmux_session" \; \
|
new-session -d -s "$tmux_session" \; \
|
||||||
set-option -t "$tmux_session" destroy-unattached off &> /dev/null
|
set-option -t "$tmux_session" destroy-unattached off &> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Attach to the 'prezto' session or to the last session used. (detach first)
|
# Attach to the session name requested in an environment variable or the default (detaching others)
|
||||||
exec tmux $_tmux_iterm_integration attach-session -d
|
exec tmux $_tmux_iterm_integration attach-session -t "$tmux_session" -d
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user