Skip to content

Latest commit

 

History

50 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tmox (Terminal Monoplexer)

Tmox spawns a shell detached from the current terminal. The detached shell stays alive even after the terminal is closed. It's almost equivalent to Tmux that spawns multiple detached shells ("multiplexer"). Instead, Tmox detaches only one shell; hence "monoplexer".

Why?

Tmox was designed for a peculiar setup as follows.

  • You don't have root.
  • You can't install any program.
  • You must hold the shell alive even after closing the terminal.

A very simple example of this peculiar setup would be using a cluster as a non-admin, where (for some reason) you need to keep your shell alive to maintain the connection to one of the cluster nodes but don't have any privileges to install extra programs to do so nor any authority to make you able to use the node anyway.

Usage

  • Run bash tmox to spawn and enter a detached shell.
  • Press Ctrl+Q to detach from the shell (still alive).
  • Run bash tmox again to re-enter the detached shell.
  • Type exit to close the detached shell.

Notes

  • Like Tmux, Tmox doesn't save the shell across reboots; the detached shell will evaporate when the system that runs the detached shell shuts down or reboots.
  • It's only about 150 lines! (About 110 lines without comments.) Go play with the code.
Click here for technical details.

Technical Details

While writing Tmox, I discovered some interesting technical details. I hope other people will find them interesting (or helpful).

Detached Interactive Shell

  • TODO: Launching an interactive shell: bash -i
  • TODO: Detaching a process from the script: nohup, set -m

Standard IO Redirection

  • TODO: Redirecting stdio: regular file, FIFO
  • TODO: "Faking" a normal pseudo-terminal: TTY/PTY, script

Terminal Interaction

  • TODO: Forwarding stdin: read, stty raw, ANSI-C quoting
  • TODO: Receiving stdout/stderr: tail
  • TODO: Handling signals: trap, Bash Control Sequence, kill 0

Miscellaneous

  • TODO: Using flock
  • TODO: Getting the current terminal dimension
Click here for known issues.

Known Issues

  • It delivers some random keystrokes upon starting up vim.
  • The re-attached shell looks trashy if TTY-manipulating programs (e.g., vim) have been opened even once.
  • It doesn't automatically resize the shell when the attached terminal changes its dimensions.

About

Deceptively simple script to detach a shell from the terminal. "Terminal Monoplexer"

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages