Terminal multiplexer

From 太極
Revision as of 15:10, 29 October 2024 by Brb (talk | contribs) (→‎Tabby)
Jump to navigation Jump to search

Resource

Ways to Keep Remote SSH Sessions and Processes Running After Disconnection

5 Ways to Keep Remote SSH Sessions and Processes Running After Disconnection

Tabby

Tilix*

Tilix is a good replacement of the default Terminal in Ubuntu. The blue color for folders in Ubuntu's Terminal make it hard to read in a dark background (quick fix by redefining the "di" value in the LS_COLORS variable). Tilix has better default colors in the dark background.

A tiling terminal emulator for Linux using GTK+ 3

  • https://gnunn1.github.io/tilix-web/ and Ubuntu PPA for the latest version.
  • Preferences:
    • Font size
      • Zoom in by Ctrl + Shift + Plus. Zoom out by Ctrl + -.
      • The other way is Preferences -> Default -> General. Check "Custom font".
    • Background image. Go to Appearance and change the 'Background Image'. We can change the theme in this dialog. Remember to change the transparency value in the "Color" tab away from 0 in order for the background to work. See Upgrade Your Linux Terminal with Tilix
    • Color: Change color them by using 'profile. The "Material" one looks good. We can also increase the Transparency .
  • Tilix: The Almost Perfect Tiling GTK+ 3 Terminal Emulator. You can save and load terminal groups, so you can easily pick up from where you left off, using the exact same terminal layout. My testing is it only saves the layout but not the directories in each pane.
  • Drag and drop file does not work with Terminator but Tilix works fine.
  • How to set Tilix as your default terminal in Pop!_OS and Ubuntu
    sudo update-alternatives --config x-terminal-emulator
    

    From the selection presented, select the option which lists tilix.wrapper. To test you have successfully changed the default to Tilix, open a terminal by pressing CTRL +Alt + T.

hyper

https://hyper.is/

Terminator

  • 20 Useful Terminal Emulators for Linux
  • https://wiki.archlinux.org/index.php/Terminator (include some keyboard shortcuts)
    • Ctrl + Shift+ O Split terminals horizontally
    • Ctrl + Shift+ E Split terminals vertically
    • mouse can be used to resize split screens and switch to each screen
  • Change the default window size
    • Method 1: it can only change the size. nano ~/.config/terminator/config
    • Method 2: it can change both the size and geometry position. --geometry parameter.
  • Change the font size. I pick 'Ubuntu Mono Regular' 14.
  • Keyboard shortcuts
    • Shift + Ctrl + p/n: switch to the previous/next view
    • Ctrl -: decrease font
    • Shift Ctrl +: increase font
  • You can take a screenshot to record the directories for all split screens.
  • Right click to open the Preferences. We can change the number of scroll back there to infinity.
  • To change the title (From the Terminator man pages),
    • Ctrl+Alt+W Rename window title.
    • Ctrl+Alt+A Rename tab title.
    • Ctrl+Alt+X Rename terminal title.

Wave Terminal

Kitty

GNU screen

How to do it...

  • Run screen command first (run sudo apt-get install screen if necessary). You are now inside of a window within screen. This functions just like a normal shell except for a few special characters.
  • Create screen windows: Ctrl + a, then c. To close a screen window: exit. Once you close all screen windows, you shall see a message [screen is terminating] on the terminal.
  • View a list of open windows: Ctrl + a, then ".
  • Switch between windows: Ctrl + a and n for the next window and Ctrl +a and p for the previous window.
  • Attaching to and detaching screens: To detach (save) from the current screen session, Ctrl +a, and d (these keyboard shortcuts won't affect current execution). This will drop you into your shell. This is useful when you need to run a time-consuming job or your connection is dropped. To attach to an existing screen, use:
screen -r -d
  • Split screen:
    • To split the screen horizontally, Ctrl +a and S (capital).
    • To unsplit the screen, Ctrl +a and Q (capital).
    • To switch from one to the other: Ctrl +a and TAB.
    • Note: After splitting, you need to go into the new region and start a new session via Ctrl + a then c before you can use that area.

tmux*

  • https://github.com/tmux/tmux/wiki
  • Syntax change from version 2 to 3. CHANGES
  • For the prefix key, ctrl+a is easier than "ctrl+b" to type. F1...F4 works too but F1 will have a conflict with Gnome Terminal.
  • How to Get Started and Use tmux
  • How to Install and Configure Tmux for Linux
  • Oh My Tmux!, which let you click between them to switch panes or resize a pane if we turn on the mouse mode (Prefix + m).
    • <prefix> + a as a secondary prefix while keeping <prefix> + b as the default prefix
    • If we pay attention enough, we will see the blue line highlighting the current pane. In the case of two horizontal panes, the left blue-line highlights the top pane and the right blue-line highlights the bottom pane.
    • When the mouse mode is on, we can use mouse to switch or resize panes or scroll back pages.
    • (Mouse method to select & copy text).
      • When the mouse mode is on, we can use mouse to select text.
      • When we release the mouse, the text is copied to a buffer.
      • We can use <Prefix> + ] or <prefix> + p to paste the text in the buffer.
      • The problem with using the mouse to copy text is we cannot scroll up.
    • (Keyboard method to select & copy text). Steps 1-5 can be done with mouse.
      1. <prefix> + [ or <prefix> + Enter to enter the copy mode.
      2. Use arrow key to go to the beginning position.
      3. <prefix> + Space to start the selection.
      4. Use arrow key to go to the end position.
      5. <prefix> + w to copy the region.
      6. <prefix> + ] or <prefix> + p to paste the selection.
    • 'q' to exit the copy mode.
  • tmux – A Powerful Terminal Multiplexer For Heavy Command-Line Linux User
  • tmux vs. GNU Screen
  • Byobu vs. GNU Screen vs. tmux — usefulness and transferability of skills
  • 4 ways to be more productive, using RStudio's terminal
  • If byobu is installed, then tmux command will start byobu (a modified tmux).
  • Byobu changed the text color of ls output while tmux does not (Ubuntu 18.04).
  • Change the default prefix key ("ctrl+b"). Note after a change on ~/.tmux.conf, we need to
    • run tmux source-file ~/.tmux.conf
    • exit the session and enter again for the change to take effect.
  • Plugin manager
  • tmux is available in biowulf/helix
  • In macOS/iTerm2, we need to open Prefs > General and check the option "Application in Terminal may access clipboard" for copy/paste to work using mouse/touchpad.

Features:

  • Split screens
  • Don't worry about connection broken (if used remotely) or computer shutdown unexpectedly (it used locally)
  • Remember the session including split screens even computer shutdown for any reason. Useful for running a long job (wget, rsync, et al).

Most important keyboard shortcuts:

Keyboard Action
(ctrl+b), ? Show key binding
(ctrl+b), "
(ctrl+b), %
split the pane horizontally,
split the pane vertically
(ctrl+b), up/down arrow key move around panes
(ctrl+b), d

exit

detach

quit a session

$ tmux ls list sessions
$ tmux attach -t 0 re-attach session 0
(ctrl+b), :

(ctrl + ⌥ )

resize-pane -U 10

resize-pane -D 10

resize-pane -R 4

resize pane

resize the current pane up (works for all four arrows)

increase pane height by 10

decrease pane height by 10

expands pane four lines to the right

(ctrl+b), [

'q' to quit

scrollback (Enter copy model)
(ctrl+b), [

Ctrl + Space

Ctrl + w

(ctrl+b), ]

$ tmux save-buffer foo.txt

copy mode

Use the arrow key to go to the top first. Select the top of the text

Use the arrow key to go to the bottom. Select the Bottom of the text and copy

Paste (works in tmux window only. To get the tmux buffer in system clipboard, see here)

Save the buffer to a file

My ~/.tmux.conf file

set -g prefix C-a  # change prefix from (C-b) to (C-a)
unbind C-b
bind C-a send-prefix
set -g mouse on                   # use mouse to scroll and switch panes
set-window-option -g mode-keys vi # for copy-paste

To exit a messed session, use (ctrl+b), d to exit the current session. Then issue tmux kill-session -t 0 to kill that session.

Save session after reboot

How To Save And Restore Tmux Environments Across Reboots In Linux

Raspberry Pi zero

It seems tmux uses too much resource. The CPU shows 100% usage. After I uninstall tmux, the CPU shows 2-3% usage.

SSH

Enhancing SSH Login With A Tmux Session Selection Menu In Linux

Byobu

Byobu is a GPLv3 open source text-based window manager and terminal multiplexer. It appeared at Think inside the box.

Resources:

Most important keyboard shortcuts:

Keyboard Action
Shift + F2 split the pane horizontally
Shift + up/down arrow key move around panes
Shift + Alt + up/down key resize panes
F6 detach

Summary:

  • Mouse is useless
  • When used with iTerm on Mac, some keys may have a different behaviors.
  • If we want to use the 'byobu' command remotely, we first run a ssh connection to a remote computer. Then we type 'byobu' to start a new session. After some operations, we can type 'exit' to quit the session or use "F6" to detach the session and return to a normal ssh connection.
  • Kill a frozen session by byobu kill-session -t 1 where "1" is the session number obtained by byobu list-session
  • Cf Session (a complete new terminal), Windows (count from 0, see the status bar), Split (also called pane)
  • Some all keyboard shotcuts rely on the Fx keys. It is not easy or may fail to do that on Mac (needs to hold the 'fn' key) keyboard on a ssh connection.
  • F1 to go to help, e.g. key bindings. ESC to go back.
    • Shift-F1 will open a new window (check the status bar for a new number). 'q' to quit the Help Window.
    • Use Alt + Left/Right to move focus among windows
  • F2 - create a new window. F3/F4 (or Alt-Left/Alt-Right) - move to previous/next window
    • Ctrl-Shift-F2 - create a new session (not work on Mac keyboard?)
    • Alt-Up/Down to move between sessions
  • Split screen
    • Horizontal (up and down): Shift + F2.
    • Vertical: Ctrl + F2.
    • Again you cannot use mouse to move the focus:(
    • Shift + Left/Right/Up/Down to move focus among splits
    • 'exit' to close a split
    • Shift-F6 to kill a split
    • Shift + Alt + arrow keys: resize split screen
  • F5 reload profile, refresh status
  • F6 Detach session and then log out (type 'byobu' to connect again). That is, even you closed a byobu window, it is still in the background. We can test it by using 'htop' or 'ping' commands.
    • Type 'ps -ef | grep byobu' in the ssh connection to find out detached byobu sessions
  • F7 Enter scrollback mode (you'll see 2 numbers [0/XXX] with a purple background at the top-right corner)
    • Move the cursor (arrow keys or Alt-PageUp/PageDown keys) to the start of the text you want to copy, hit Space
    • Move the cursor to the end of the text you want to copy and hit Enter
    • To paste text, open a text editor in the same byobu terminal and hit Alt + Insert or ctrl-a-]. The first time to use ctrl-a, we need to choose either Screen or Emacs mode (I choose Screen). Use byobu-ctrl-a to reconfigure change this selection. See Ubuntu page.
    • Alt-PageUp/PageDown - enter and move through scrollback (fn+Alt+Up/Down on Mac keyboard)
    • Press Enter key to exit
  • F8 Rename the current window
    • Shift-F8 Rename the current session (not work on Mac keyboard)
  • F11
    • Shift-F11 Zoom in/out a split
    • Alt-F11 Break a split to a full window
  • F12
    • Shift-F12 Toggle on/off Byobu's keybindings (say, Byobu's keybindings conflict with some other program)
    • Alt-F12 Toggle on/off Byobu's mouse support (move around splits and resize split size). It becomes more complex when we want to select text.
Byobu.png

Guake

Zellij

Zellij Rust Terminal Multiplexer 0.12.0 Released With Detachable / Persistent Sessions