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

Disable auto-start for multiplexers with SSH #292

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions modules/screen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ To enable this feature, add the following line to *zpreztorc*:

zstyle ':prezto:module:screen' auto-start 'yes'

#### SSH and auto-start

To avoid having screen sessions inside screen sessions, auto-start is disabled for
SSH access.

It is possible to re-enable auto-start for SSH sessions with

zstyle ':prezto:module:screen' remote 'yes'

Aliases
-------

Expand Down
3 changes: 2 additions & 1 deletion modules/screen/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ fi
# Auto Start
#

if [[ -z "$STY" ]] && zstyle -t ':prezto:module:screen' auto-start; then
if ( [[ -z "$SSH_CLIENT" ]] || zstyle -t ':prezto:module:screen' remote ) &&
( [[ -z "$STY" ]] && zstyle -t ':prezto:module:screen' auto-start ); then
session="$(
screen -list 2> /dev/null \
| sed '1d;$d' \
Expand Down
9 changes: 9 additions & 0 deletions modules/tmux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ To avoid keeping open sessions, this module sets `destroy-unattached off` on
the background session and `destroy-unattached on` on every other session
(global setting).

#### SSH and auto-start

To avoid having tmux sessions inside tmux sessions, auto-start is disabled for
SSH access.

It is possible to re-enable auto-start for SSH sessions with

zstyle ':prezto:module:tmux' remote 'yes'

Aliases
-------

Expand Down
3 changes: 2 additions & 1 deletion modules/tmux/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ fi
# Auto Start
#

if [[ -z "$TMUX" ]] && zstyle -t ':prezto:module:tmux' auto-start; then
if ( [[ -z "$SSH_CLIENT" ]] || zstyle -t ':prezto:module:tmux' remote ) &&
( [[ -z "$TMUX" ]] && zstyle -t ':prezto:module:tmux' auto-start ); then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if statement is a bit hard to read. It looks to me like it fails on localhost if remote is not set to true.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understood it after I translated it to something more readable.

( is-false "$_screen_is_on_remote" || is-true "$_screen_auto_start_on_remote" ) && ( is-false "$_screen_is_started" && is-true "$_screen_auto_start")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically:

If we are not in a SSH (remote) session or if starting the multiplexer in a SSH (remote) session is enabled
and, if the multiplexer isn't started and if auto-start is enabled.

tmux_session='#Prezto'

if ! tmux has-session -t "$tmux_session" 2> /dev/null; then
Expand Down
5 changes: 5 additions & 0 deletions runcoms/zpreztorc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ zstyle ':prezto:module:prompt' theme 'sorin'
# Auto start a session when Zsh is launched.
# zstyle ':prezto:module:screen' auto-start 'yes'

# Allow auto-start with an SSH connection
# zstyle ':prezto:module:screen' remote 'yes'

#
# SSH-Agent
#
Expand Down Expand Up @@ -118,3 +121,5 @@ zstyle ':prezto:module:terminal' auto-title 'yes'
# Auto start a session when Zsh is launched.
# zstyle ':prezto:module:tmux' auto-start 'yes'

# Allow auto-start with an SSH connection
# zstyle ':prezto:module:tmux' remote 'yes'