
C-a
Ubuntu 10.04 に tmux をインストールし、次の行を含むファイルを作成してプレフィックス キーを再マップしようとしました~/.tmux.conf
。
set-option -g prefix C-a
unbind-key C-b
tmuxを起動する場合、通常でも を使っても-f ~/.tmux.conf
、プレフィックスは実質的に同じデフォルトです。C-b
エラーや警告は一切ありません。
conf の読み込みで何が問題になっているのかご存知ですか?
答え1
~/.tmux.conf ファイルは、tmux サーバーが最初に起動されたときに読み込まれます。そのため、既存の tmux セッションがある場合、新しいセッションを開始してもtmux
.tmux.conf ファイルは再読み込みされません。tmux サーバーを再起動してみてください。コマンドを使用して、tmux list-sessions
既存のセッションがあるかどうかを確認します。それらを終了します (たとえばtmux attach
、すべてのウィンドウを終了して終了します)。すべてのセッションがなくなったら、tmux
もう一度試してください。今回は再バインドが機能するはずです。
答え2
セッションを終了せずに ~/.tmux.conf をリロードするには、次のようにします。
<prefix> :source-file /absolute/path/to/your/.tmux.conf
デフォルトでは<prefix>
です。<C-b>
答え3
tmux セッション内で実行します:
tmux source-file /absolute/path/to/your/.tmux.conf
答え4
12年前
私にとってはうまくいきました。 を実行し
strace -s9999 -f -o tmux.strace tmux -c true
て出力を投稿してくださいgrep -C5 'tmux\.conf' tmux.strace
。 – Gilles 'SO- stop being evil' 2010 年 9 月 14 日 20:24
控えめな表現のマスタークラス
彼らは大騒ぎすることなく、コメントに1文だけ残した。答えしかし、答え. だけでなく答えこの質問に対して、しかし参考回答一連の質問全体に対して。
詳しく見る
どういうstrace -s9999 -f -o tmux.strace tmux -c true
意味?
これは、2 つのコマンドを 1 つにまとめたようなものです。メイン コマンドは ですtmux
が、 という「プレフィックス」/「ラッパー」が付けられます。これは、コマンドの実行にかかる時間を測定する のstrace
実行に非常に似ています。time df
df
strace
-s9999
-f
-o tmux.strace
$ man strace | grep -A1 ^NAME
NAME
strace - trace system calls and signals
$ man strace | grep -EA10 '^ *DESCRIPTION($| )'
DESCRIPTION
In the simplest case strace runs the specified command until it exits. It
intercepts and records the system calls which are called by a process and
the signals which are received by a process. The name of each system call,
its arguments and its return value are printed on standard error or to the
file specified with the -o option.
strace is a useful diagnostic, instructional, and debugging tool. System
administrators, diagnosticians and trouble-shooters will find it invaluable
for solving problems with programs for which the source is not readily
available since they do not need to be recompiled in order to trace them.
$ man strace | grep -EA4 '^ *-s($| )'
-s strsize
--string-limit=strsize
Specify the maximum string size to print (the default is 32).
Note that filenames are not considered strings and are always
printed in full.
$ man strace | grep -EA6 '^ *-f($| )'
-f
--follow-forks
Trace child processes as they are created by currently traced
processes as a result of the fork(2), vfork(2) and clone(2) sys‐
tem calls. Note that -p PID -f will attach all threads of
process PID if it is multi-threaded, not only thread with
thread_id = PID.
$ man strace | grep -EA8 '^ *-o($| )'
-o filename
--output=filename
Write the trace output to the file filename rather than to
stderr. filename.pid form is used if -ff option is supplied.
If the argument begins with '|' or '!', the rest of the argument
is treated as a command and all output is piped to it. This is
convenient for piping the debugging output to a program without
affecting the redirections of executed programs. The latter is
not compatible with -ff option currently.
tmux
-c true
$ man tmux | grep -EA4 '^ *-c($| [^ ]*$)'
-c shell-command
Execute shell-command using the default shell. If necessary,
the tmux server will be started to retrieve the default-shell
option. This option is for compatibility with sh(1) when tmux
is used as a login shell.
$ man true | grep -A1 ^NAME
NAME
true - do nothing, successfully
なぜ...
-c
tmux と一緒に使用しますか?
の起動プロセスだけを気にしているのでtmux
、対話的に使用する必要はありません。したがって、通常の対話型シェルの代わりにコマンドを実行するように指示します。
true
tmux コマンドとして使用しますか?
非常に速く終了し、ログを短く保つことができるためです。
-o tmux.strace
strace と一緒に使用しますか?
これは出力を保存するだけのファイルです。名前を付けるのは難しいです。ベース名や拡張子を他のものと一致させることは重要ではありませんでした。
-f
strace と一緒に使用しますか?
マニュアルページからの抜粋を読んで、冗長化するある程度複雑なアプリケーションであれば、子プロセスが作成されます。tmux
非常に複雑なため、子プロセスも strace する必要があります。
-s9999
strace と一緒に使用しますか?
出力をファイルに書き込むため、端末の幅に合わせて行を切り捨てる必要はありません。大きく設定してください。問題がある場合は、後で表示するように対処してください。
なぜかこれらのいずれか?
もしどれでもつまり、この長い答えを書くということですか...
- なぜなら、私はエンジニアリング チームをトレーニングしており、彼らにこの答えを教えるからです。
- だってジャイルズ…
- すごいヒーローだ
- 10年以上コメントに賛成票が0だった
- 長い間気づかれずにいたが、私はこのまま放置するつもりはない
このプロセスがなぜ必要なのか分からない場合は道次のような質問に答えるには 「conf の読み込みで何が問題になっているのか分かりますか?」 それでしたら、XY問題
それは質問者XY問題に陥る人々。非常に~この間違いを犯します~ に対する回答では、これもよくあります。この場合、この質問に対する多くの回答では、プロセスの開始後に構成ファイルをロード/再ロードする方法を読者に指示しています。これは、プロセスがファイルを正しくロードできないという事実を無視することを示唆しています。
ここまで読んでいただいた方に、失敗を無視しても問題ないのは次のような場合だけだということをご理解いただきたいと思います。
- 妨害者を乗り越えて、自分自身が他者の妨害者でなくなるようにする
- 後で戻ってきて問題を正しく修正します
まとめ
多くの問題は、「ファイルの読み込みで何が問題なのか?」という点に集約できます。この質問は、「ファイルを読み込もうとしているのか? 読み込もうとすると何が起きるのか?」という形でスパイダーマンの感覚を刺激するはずです。
strace
次のように疑問視される可能性のあるものはすべて解決できます/すべきです:
- このプロセスは何をしようとしているのでしょうか?
- とはそれそれが[やろうとしていること]をやろうとしているときに、どのような経験をするのでしょうか?
多くの場合、それはプロセスの失敗ではない何かをするが、ユーザーの失敗プロセスが何かを実行することを期待します。そして、プロセスはユーザーに通知されない多くのことを経験します。
抽象的な説教はもう十分です。例を考えてみましょう。
$ tmux kill-server; rm tmux.strace; strace -s9999 -f -o tmux.strace tmux -c true
no server running on /tmp/tmux-1000/default
$ ls -lh tmux*
-rw-r--r-- 1 bruno bruno 21K Jun 11 10:58 tmux-client-18358.log
-rw-r--r-- 1 bruno bruno 324M Jun 11 10:58 tmux-server-18360.log
-rw-r--r-- 1 bruno bruno 342K Jun 11 13:48 tmux.strace
$ grep 'tmux\.conf' tmux.strace
521744 readlink("/etc/tmux.conf", 0x7ffe2c0446d0, 1023) = -1 ENOENT (No such file or directory)
521744 readlink("/home/bruno/.tmux.conf", 0x7ffe2c0446d0, 1023) = -1 ENOENT (No such file or directory)
521744 readlink("/home/bruno/.config/tmux/tmux.conf", 0x7ffe2c0446d0, 1023) = -1 ENOENT (No such file or directory)
$ ls -lA /home/bruno/.config/tmux
-rw-r--r-- 1 bruno bruno 307 Jun 10 20:29 tmux.config
わかりますか? 最後の 2 つのコマンドの出力を見てください。 修正方法を示すと役立つかもしれません。
$ mv ~/.config/tmux/tmux.config \
~/.config/tmux/tmux.conf
$ tmux kill-server; rm tmux.strace; strace -s9999 -f -o tmux.strace tmux -c true
no server running on /tmp/tmux-1000/default
$ grep -A2 '\.config/tmux/tmux\.conf' tmux.strace
527872 openat(AT_FDCWD, "/home/bruno/.config/tmux/tmux.conf", O_RDONLY) = 8
527872 newfstatat(8, "", {st_mode=S_IFREG|0644, st_size=307, ...}, AT_EMPTY_PATH) = 0
527872 read(8, "set -sg escape-time 0\nset -g mode-keys vi\n\n# remap prefix from 'C-b' to 'C-f'\nset-option -g prefix C-f\nunbind-key C-b\nbind-key C-f send-prefix\n\n# split panes using | and -\nbind | split-window -h\nbind - split-window -v\n# bind \"\33OA\" # scroll natural up\n# bind \"\33OB\" # scroll natural down\nunbind '\"'\nunbind %\n\n", 4096) = 307
注: 最後の行は、(以前は名前が間違っていた) ファイルの全内容です~/.config/tmux/tmux.conf
。