Giter Club home page Giter Club logo

tmux-suspend's Introduction

Tmux Suspend

Plugin that lets you suspend local tmux session, so that you can work with nested remote tmux session painlessly.

Demo:

Tmux Suspend Demo GIF

Usage

With the default keybinding,

Press F12 to suspend your local tmux session. In suspeded state, you can only interact with the currently active pane (which will be running the remote tmux session).

Press F12 again in suspended state to resume local tmux session.

Note: If you have tmux-mode-indicator plugin installed, it'll automatically show indicator for the suspended state.

Installation

Installation with Tmux Plugin Manager

Add this repository as a TPM plugin in your .tmux.conf file:

set -g @plugin 'MunifTanjim/tmux-suspend'

Press prefix + I in Tmux environment to install it.

Manual Installation

Clone this repository:

git clone https://github.com/MunifTanjim/tmux-suspend.git ~/.tmux/plugins/tmux-suspend

Add this line in your .tmux.conf file:

run-shell ~/.tmux/plugins/tmux-suspend/suspend.tmux

Reload Tmux configuration file with:

tmux source-file ~/.tmux.conf

Configuration Options

The following configuration options are available:

@suspend_key

Key used to suspend/resume local tmux session. This is not binded to any Prefix.

set -g @suspend_key 'F12'

@suspend_suspended_options

Comma-seperated list of items denoting options to set for suspended state. These options will be automatically reverted when session is resumed.

set -g @suspend_suspended_options " \
  @mode_indicator_custom_prompt:: ---- , \
  @mode_indicator_custom_mode_style::bg=brightblack\\,fg=black, \
"

The syntax of each item is #{option_name}:#{option_flags}:#{option_value}.

Item Segment Description
#{option_name} name of the option.
#{option_flags} flags accepted by set-option, can be left empty.
#{option_value} value of the option, commas (,) inside value need to be escaped as \\,

For example:

# remove colors from status line for suspended state
set -g @suspend_suspended_options " \
  status-left-style::bg=brightblack\\,fg=black bold dim, \
  window-status-current-style:gw:bg=brightblack\\,fg=black, \
  window-status-last-style:gw:fg=brightblack, \
  window-status-style:gw:bg=black\\,fg=brightblack, \
  @mode_indicator_custom_prompt:: ---- , \
  @mode_indicator_custom_mode_style::bg=brightblack\\,fg=black, \
"

@suspend_on_suspend_command and @suspend_on_resume_command

These options can be set to arbritary commands to run when session is suspended (@suspend_on_suspend_command) or resumed (@suspend_on_resume_command).

set -g @suspend_on_resume_command ""
set -g @suspend_on_suspend_command ""

For example, you can do the same thing that the default value of @suspend_suspended_options does using these options instead:

set -g @suspend_suspended_options ""

set -g @suspend_on_resume_command "tmux \
  set-option -uq '@mode_indicator_custom_prompt' \\; \
  set-option -uq '@mode_indicator_custom_mode_style'"

set -g @suspend_on_suspend_command "tmux \
  set-option -q '@mode_indicator_custom_prompt' ' ---- ' \\; \
  set-option -q '@mode_indicator_custom_mode_style' 'bg=brightblack,fg=black'"

As you can see, it's more convenient to use @suspend_suspended_options for setting and reverting options.

License

Licensed under the MIT License. Check the LICENSE file for details.

tmux-suspend's People

Contributors

muniftanjim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tmux-suspend's Issues

how to configure status format option

I can't figure out how to configure options like status-right in the @suspend_suspended_options configuration.

set -g @suspend_suspended_options " \
  @mode_indicator_custom_prompt:: ---- , \
  @mode_indicator_custom_mode_style::bg=brightblack\\,fg=black, \
  status-right::#{tmux_mode_indicator} [fg=colour15,bg=colour136]#{?window_zoomed_flag, ZOOM ,}#[default] [fg=colour136]#(whoami)#[default]@#H | [fg=colour136]%h %d %H:%M:%S#[default] #{online_status}, \
  status-style::bg=brightblack\\,fg=colour15, \
  window-status-current-style::bg=colour245\\,fg=colour15, \
"

This code fails at the status-right line

Support for custom/multiple prefix keys?

I am trying to use this plugin, however in my setup, I use C-a as prefix2 (so both C-b and C-a work as prefix keys), however, this plugin only suspends the outer session when attempting to use C-b.

Is it possible to support custom or multiple prefix keys?

How to get current session when suspending

I would like to set an option only for the current session when I suspend. However, I'm not sure how to get the current tmux session.

set -g @suspend_on_resume_command " \
  session=$(tmux display-message -p '#S'); \
  tmux set -qt $session @catppuccin_status_modules_right 'directory user host session'; \
  tmux run '~/.config/tmux/plugins/tpm/tpm'; \
  "

set -g @suspend_on_suspend_command " \
  session=$(tmux display-message -p '#S'); \
  echo $session > ~/.tmux_suspend_session; \
  tmux set -qt $session @catppuccin_status_modules_right 'user host session'; \
  tmux run '~/.config/tmux/plugins/tpm/tpm'; \
  "

~/.tmux_suspend_session is empty after suspending, because I think tmux is executing this outside of the session. Or if you have a better way of only changing an option for a single session, that would also be helpful.

Support smarter options reverting on resume

Currently options set in @suspend_on_suspend_command needs to be manually reverted in @suspend_on_resume_command.

This leads to duplication in tmux config file. There needs to be a smarter alternative where options set for suspended state are automatically reverted to pre-suspend values when resumed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.