linux:tmux

tmux - terminal multiplexer (端末多重接続ソフトウェア)

tmux 画面
本家: Home · tmux/tmux Wiki (翻訳)
ソースコード: tmux/tmux: tmux source code
ドキュメント: TMUX Guide — TMUX Guide documentation (翻訳)
Linux manual: tmux(1) - Linux manual page (翻訳)
Arch Linux: tmux - ArchWiki

tmux とは、Unix ライクなオペレーティングシステム用の端末多重接続ソフトウェアである。
単一のウィンドウで複数の端末セッションにアクセスできる。同時に複数のコマンドラインプログラムを実行する際に有用である。
tmux は制御端末からプロセスを切断することもでき、SSH セッションを SSH 接続をしていない状態でも維持することができる。
Wikiwand - Tmux より

  • Ctrl + b を入力後 ? でキーバインド一覧
  • Ctrl + b を入力後 d でセッションをデタッチ(セッションを残した状態で tmux 実行前のセッションに戻る)
  • Ctrl + b を入力後 Shift + 2 (“) で上下に分割
  • Ctrl + b を入力後 Shift + 5 (%) で左右に分割
  • Ctrl + b を入力後 or or or でペイン移動
  • Ctrl + b を入力後 Space を繰り返すとお好みのレイアウトに
  • Ctrl + b を入力後 [ (上スクロール)、 (下スクロール)、Page UPPage Down
  • Ctrl + b を入力後 { で前の画面に入れ替え
  • Ctrl + b を入力後 } で後の画面に入れ替え
  • Ctrl + b を入力後 Ctrl + ↑ or ↓ or ← or → で画面のサイズ変更

attach-session [-dErx] [-c working-directory] [-f flags] [-t target-session] (alias: attach)
$ tmux a
$ tmux a -t 0

detach-client [-aP] [-E shell-command] [-s target-session] [-t target-client] (alias: detach)
$ tmux det -s 0

$ tmux ls

0: 1 windows (created Fri Oct 14 14:47:17 2022) [110x45]
1: 1 windows (created Fri Oct 14 14:49:39 2022) [237x35] (attached)

$ tmux det -s 1
$ tmux ls

0: 1 windows (created Fri Oct 14 14:47:17 2022) [110x45]
1: 1 windows (created Fri Oct 14 14:49:39 2022) [237x35]

  • Ctrl + b を入力後 d で現在のセッションをデタッチ
    デタッチしたセッションは ssh をログアウト後もマシンに残り続ける。

ssh 再接続後にアタッチできる。
セッションを確認するには…

$ tmux ls

0: 1 windows (created Thu Jun 11 04:44:30 2020)

$ tmux a
$ tmux a -t 0

$ tmux ls

0: 1 windows (created Thu Jun 11 04:44:30 2020)

$ tmux kill-session
$ tmux ls

no server running on /tmp/tmux-1000/default

$ nano ~/.tmux.conf

#マウス操作有効化
set -g mouse on
#スクロールバック行数
set-option -g history-limit 100000

libtmux - tmux を制御するための Python スクリプトライブラリ

libtmux をインストールする🤔

$ pip install --user libtmux

Collecting libtmux
  Downloading libtmux-0.21.0-py3-none-any.whl (47 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 47.5/47.5 kB 296.3 kB/s eta 0:00:00
Installing collected packages: libtmux
Successfully installed libtmux-0.21.0

ptpython をインストールする🤔

$ pip install --user ptpython

Collecting ptpython
  Downloading ptpython-3.0.23-py2.py3-none-any.whl (63 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.0/64.0 kB 340.0 kB/s eta 0:00:00
Collecting appdirs
  Downloading appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Collecting jedi>=0.16.0
  Using cached jedi-0.18.2-py2.py3-none-any.whl (1.6 MB)
Collecting prompt-toolkit<3.1.0,>=3.0.28
  Using cached prompt_toolkit-3.0.38-py3-none-any.whl (385 kB)
Collecting pygments
  Using cached Pygments-2.14.0-py3-none-any.whl (1.1 MB)
Collecting parso<0.9.0,>=0.8.0
  Using cached parso-0.8.3-py2.py3-none-any.whl (100 kB)
Collecting wcwidth
  Using cached wcwidth-0.2.6-py2.py3-none-any.whl (29 kB)
Installing collected packages: wcwidth, appdirs, pygments, prompt-toolkit, parso, jedi, ptpython
Successfully installed appdirs-1.4.4 jedi-0.18.2 parso-0.8.3 prompt-toolkit-3.0.38 ptpython-3.0.23 pygments-2.14.0 wcwidth-0.2.6

  • linux/tmux.txt
  • 最終更新: 2023/04/23 07:07
  • by ともやん