~~CLOSETOC~~ ====== tmux - terminal multiplexer (端末多重接続ソフトウェア) ====== {{windows:wsl_tmux.png?470|tmux 画面}}\\ 本家: [[ghi>tmux|Home · tmux/tmux Wiki]] ([[https://github-com.translate.goog/tmux/tmux/wiki?_x_tr_sl=en&_x_tr_tl=ja&_x_tr_hl=ja&_x_tr_pto=sc|翻訳]])\\ ソースコード: [[git>tmux/tmux|tmux/tmux: tmux source code]]\\ ドキュメント: [[rtd>tmuxguide.readthedocs.io|TMUX Guide — TMUX Guide documentation]] ([[https://tmuxguide-readthedocs-io.translate.goog/en/latest/tmux/tmux.html?_x_tr_sl=en&_x_tr_tl=ja&_x_tr_hl=ja&_x_tr_pto=sc|翻訳]])\\ Linux manual: [[https://man7.org/linux/man-pages/man1/tmux.1.html|tmux(1) - Linux manual page]] ([[https://man7-org.translate.goog/linux/man-pages/man1/tmux.1.html?_x_tr_sl=en&_x_tr_tl=ja&_x_tr_hl=ja&_x_tr_pto=sc|翻訳]])\\ Arch Linux: [[arc>Tmux|tmux - ArchWiki]]\\ **tmux** とは、Unix ライクなオペレーティングシステム用の端末多重接続ソフトウェアである。\\ 単一のウィンドウで複数の端末セッションにアクセスできる。同時に複数のコマンドラインプログラムを実行する際に有用である。\\ tmux は制御端末からプロセスを切断することもでき、SSH セッションを SSH 接続をしていない状態でも維持することができる。\\ [[wwjp>Tmux|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 UP**、**Page 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
===== Python の libtmux で tmux を操作する ===== [[python:libtmux|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
===== 参考文献 ===== [[https://wiki.archlinux.jp/index.php/Tmux|tmux - ArchWiki]]\\ [[https://libtmux.git-pull.com|libtmux]]\\ [[https://www.hostinger.com/tutorials/tmux-beginners-guide-and-cheat-sheet/|tmux: How to Install and Use It + Cheat Sheet]] ([[https://www-hostinger-com.translate.goog/tutorials/tmux-beginners-guide-and-cheat-sheet/?_x_tr_sl=en&_x_tr_tl=ja&_x_tr_hl=ja&_x_tr_pto=sc|翻訳]])\\ ==== 付録 ==== [[tw>tomoyan596sp/status/1636109800965828608|tmuxをpythonから操作するのに、このようなライブラリが存在していても、国内の検索上位は「5年が経過しています」だそうです😅海外の動向しか見ないことにしてます🤔]]\\