~~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
===== キーバインド一覧 ===== ^ キー ^ 説明 ^^ | Ctrl+b Space | Select next layout | 次のレイアウトを選択します | | Ctrl+b ! | Break pane to a new window | ペインを新しいウィンドウに分けます | | Ctrl+b " | Split window vertically | ウィンドウを垂直に分割します | | Ctrl+b # | List all paste buffers | すべての貼り付けバッファーをリストします | | Ctrl+b $ | Rename current session | 現在のセッションを変更します | | Ctrl+b % | Split window horizontally | ウィンドウを水平に分割します | | Ctrl+b & | Kill current window | 現在のウィンドウを終了します | | Ctrl+b ' | Prompt for window index to select | インデックスを選択するためのプロンプト | | Ctrl+b ( | Switch to previous client | 前のクライアントに切り替えます | | Ctrl+b ) | Switch to next client | 次のクライアントに切り替えます | | Ctrl+b , | Rename current window | 現在のウィンドウを変更します | | Ctrl+b - | Delete the most recent paste buffer | 最新の貼り付けバッファーを削除します | | Ctrl+b . | Move the current window | 現在のウィンドウを移動します | | Ctrl+b / | Describe key binding | キーバインディングを説明します | | Ctrl+b 0 | Select window 0 | ウィンドウ0 を選択します | | Ctrl+b 1 | Select window 1 | ウィンドウ1 を選択します | | Ctrl+b 2 | Select window 2 | ウィンドウ2 を選択します | | Ctrl+b 3 | Select window 3 | ウィンドウ3 を選択します | | Ctrl+b 4 | Select window 4 | ウィンドウ4 を選択します | | Ctrl+b 5 | Select window 5 | ウィンドウ5 を選択します | | Ctrl+b 6 | Select window 6 | ウィンドウ6 を選択します | | Ctrl+b 7 | Select window 7 | ウィンドウ7 を選択します | | Ctrl+b 8 | Select window 8 | ウィンドウ8 を選択します | | Ctrl+b 9 | Select window 9 | ウィンドウ9 を選択します | | Ctrl+b : | Prompt for a command | コマンドのプロンプト | | Ctrl+b ; | Move to the previously active pane | 以前にアクティブなペインに移動します | | Ctrl+b = | Choose a paste buffer from a list | リストから貼り付けバッファーを選択します | | Ctrl+b ? | List key bindings | キーバインディングをリストします | | Ctrl+b C | Customize options | オプションをカスタマイズします | | Ctrl+b D | Choose and detach a client from a list | リストからクライアントを選択して取り外します | | Ctrl+b E | Spread panes out evenly | ペインを均等に広げます | | Ctrl+b L | Switch to the last client | 最後のクライアントに切り替えます | | Ctrl+b M | Clear the marked pane | マークされたペインをクリアします | | Ctrl+b [ | Enter copy mode | コピーモードを入力します | | Ctrl+b ] | Paste the most recent paste buffer | 最新のペーストバッファーを貼り付けます | | Ctrl+b c | Create a new window | 新しいウィンドウを作成します | | Ctrl+b d | Detach the current client | 現在のクライアントをデタッチします | | Ctrl+b f | Search for a pane | ペインを検索します | | Ctrl+b i | Display window information | ウィンドウ情報を表示します | | Ctrl+b l | Select the previously current window | 以前の現在のウィンドウを選択します | | Ctrl+b m | Toggle the marked pane | マークされたペインを切り替えます | | Ctrl+b n | Select the next window | 次のウィンドウを選択します | | Ctrl+b o | Select the next pane | 次のペインを選択します | | Ctrl+b p | Select the previous window | 前のウィンドウを選択します | | Ctrl+b q | Display pane numbers | ペイン番号を表示します | | Ctrl+b r | Redraw the current client | 現在のクライアントを再描画します | | Ctrl+b s | Choose a session from a list | リストからセッションを選択します | | Ctrl+b t | Show a clock | 時計を表示します | | Ctrl+b w | Choose a window from a list | リストからウィンドウを選択します | | Ctrl+b x | Kill the active pane | アクティブペインを終了します | | Ctrl+b z | Zoom the active pane | アクティブペインをズームします | | Ctrl+b { | Swap the active pane with the pane above | アクティブペインを上のペインと交換します | | Ctrl+b } | Swap the active pane with the pane below | アクティブペインを下のペインと交換します | | Ctrl+b ~ | Show messages | メッセージを表示します | | Ctrl+b DC | Reset so the visible part of the window follows the cursor | ウィンドウの可視部分がカーソルに続くようにリセットするように | | Ctrl+b PPage | Enter copy mode and scroll up | コピーモードを入力してスクロールアップします | | Ctrl+b Up | Select the pane above the active pane | アクティブペインの上のペインを選択します | | Ctrl+b Down | Select the pane below the active pane | アクティブペインの下のペインを選択します | | Ctrl+b Left | Select the pane to the left of the active pane | アクティブペインの左側のペインを選択します | | Ctrl+b Right | Select the pane to the right of the active pane | アクティブペインの右側にあるペインを選択します | | Ctrl+b Alt+1 | Set the even-horizontal layout | 均等な水平レイアウトを設定します | | Ctrl+b Alt+2 | Set the even-vertical layout | 均一なレイアウトを設定します | | Ctrl+b Alt+3 | Set the main-horizontal layout | メイン水平レイアウトを設定します | | Ctrl+b Alt+4 | Set the main-vertical layout | メイン垂直レイアウトを設定します | | Ctrl+b Alt+5 | Select the tiled layout | タイルレイアウトを選択します | | Ctrl+b Alt+6 | Set the main-horizontal-mirrored layout | メイン水平ミラーレイアウトを設定します | | Ctrl+b Alt+7 | Set the main-vertical-mirrored layout | メイン垂直ミラーレイアウトを設定します | | Ctrl+b Alt+n | Select the next window with an alert | アラートで次のウィンドウを選択します | | Ctrl+b Alt+o | Rotate through the panes in reverse | ペインを逆に回転させます | | Ctrl+b Alt+p | Select the previous window with an alert | アラートで前のウィンドウを選択します | | Ctrl+b Alt+Up | Resize the pane up by 5 | ペイン上を5にサイズ変更します | | Ctrl+b Alt+Down | Resize the pane down by 5 | ペイン下を5にサイズ変更します | | Ctrl+b Alt+Left | Resize the pane left by 5 | ペイン左を5にサイズ変更します | | Ctrl+b Alt+Right | Resize the pane right by 5 | ペイン右を5にサイズ変更します | | Ctrl+b Ctrl+b | Send the prefix key | プレフィックスキーを送信します | | Ctrl+b Ctrl+o | Rotate through the panes | ペインを通って回転させます | | Ctrl+b Ctrl+z | Suspend the current client | 現在のクライアントを一時停止します | | Ctrl+b Ctrl+Up | Resize the pane up | ペイン上をサイズ変更します | | Ctrl+b Ctrl+Down | Resize the pane down | ペイン下をサイズ変更します | | Ctrl+b Ctrl+Left | Resize the pane left | ペイン左をサイズ変更します | | Ctrl+b Ctrl+Right | Resize the pane right | ペイン右をサイズ変更します | | Ctrl+b Super+Up | Move the visible part of the window up | ウィンドウ上の可視部分を移動します | | Ctrl+b Super+Down | Move the visible part of the window down | ウィンドウ下の可視部分を移動します | | Ctrl+b Super+Left | Move the visible part of the window left | ウィンドウ左の可視部分を移動します | | Ctrl+b Super+Right | Move the visible part of the window right | ウィンドウ右の可視部分を移動します | ===== 参考文献 ===== [[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年が経過しています」だそうです😅海外の動向しか見ないことにしてます🤔]]\\