Skip to main content

control-tmux

This is a wrapper around tmux that allows you to quickly switch between sessions, save sessions while preserving bash history.

Requirements

  • Python 3.6 or higher with PIP. On Ubuntu, run sudo apt install python3-pip.
  • Tmux 3.0a or higher. On Ubuntu, run sudo apt install tmux.
  • Bash 4.0 or higher (probably works with older versions, but not tested)

Installation

control-tmux can be installed using PIP:

python3 -m pip install control-tmux

In order to use the save and restore features, you must set it up in .bashrc for each user. Simply run:

python3 -m controltmux --setup t

This will install tmux.setup.sh and tmux.default.conf in your home directory, and add references to them to .bashrc and .tmux.conf.

You can specify one or more aliases to set up for control-tmux. I recommend t because it is short and easy to type, but power users might already have an alias configured. I use scn as an alias because this project started out many years ago as a wrapper for GNU screen. Aliases will only apply to terminals opened in the future, but you can run exec bash to reload your aliases in an existing terminal.

The installer will also create a default .tmux.conf if you don't have one. This configuration is not necessary for control-tmux to run, but includes many bindings that make tmux easier to use.

Simple usage

These usage examples all assume you have aliased t to control-tmux during installatin

If run without arguments, t or control-tmux will list all your current sessions:

To start or switch to a session named blah, just run t blah:

This works whether you are running from within tmux or outside of it. If run from outside, this runs either tmux attach -t blah or tmux new-session -s blah (if blah doesn't exist) . If run from inside tmux, then it does tmux switch-client -t blah, which switches your current client to the session named blah.

In either case, this will detach any other terminals that are connected to blah, unless you prefix the session name with n (e.g. t n blah)

To save the blah session to ~/.tmuxsave/blah.zip, run t s blah. To restore, run t r blah. Restore only works when the session doesn't already exist. You can save all open sessions by running t s all:

Restoring a session restores the current working directory and the command history of the shell running within it. It does not automatically restart any commands that were running.

Recovering from a crash

The bash hooks in .tmux.setup.sh write your history to disk as soon as you launch a command. In most cases, after a power failure or crash, the session data will be recoverable. All you need to do is run t s all before running tmux.

If you forget and try to run t <session> before t s all, then it will start a new instance of tmux and running t s all will save the sessions from the new index. However, the data for the old session is still present in ~/.tmuxsave. Run ls -ld ~/.tmuxsave/tmux-default-* to see all previous sessions. Each directory will have a timestamp indicating when that particular instance of tmux was started. Once you have that directory, just run t -s ~/.tmuxsave/tmux-default-2018-XX-XX__XX-XX-XX s all and it will save the sessions from the previous instance.

Metadata

Release files for control-tmux 0.0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for control-tmux 0.0.13
File Size Uploaded
control_tmux-0.0.13.tar.gz 19.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for control-tmux 0.0.13
File Interpreter ABI Platform
control_tmux-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 49.6 kB

Release files / control_tmux-0.0.13.tar.gz

Download URL control_tmux-0.0.13.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8ebf14d8e1be3eb03da888a388eda9b7986bb5c01cb5e218d0b0abb35b977912
BLAKE2b-256 checksum
How to use checksums
8f6950c6e76b2823464e5a18953028856b302af3ca7eb433717958a581953195
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / control_tmux-0.0.13-py3-none-any.whl

Download URL control_tmux-0.0.13-py3-none-any.whl
Size 29.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
302a5a1fbab54d0ca9ad9e69682a49d5cac565af8c616bf5abd8d328bd6315ce
BLAKE2b-256 checksum
How to use checksums
3c6268b15840d1cf3a482b33bd7269cd12621e17269a87290959303ae161f68b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 release files

0.0.12

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page