
我剛剛在 Ubuntu 10.04 上安裝了 tmux 並嘗試透過使用以下行C-a
建立檔案來重新映射前綴鍵:~/.tmux.conf
set-option -g prefix C-a
unbind-key C-b
當啟動 tmux 時,無論是常規還是使用-f ~/.tmux.conf
,前綴實際上都是相同的預設值C-b
沒有任何錯誤或警告。
知道載入conf 有什麼問題嗎?
答案1
當 tmux 伺服器首次啟動時,會載入 ~/.tmux.conf 檔案。因此,如果存在現有 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- 別再作惡了' 2010 年 9 月 14 日 20:24
輕描淡寫的大師班
他們在沒有大張旗鼓的情況下在評論中丟掉了一句話,這本應該是,不僅一個答案但,答案。不僅答案對於這個問題,但是參考答案到一整類問題。
分解它
這是什麼strace -s9999 -f -o tmux.strace tmux -c true
意思?
tmux
它有點像 1 中的 2 個命令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
,因此我們不需要互動地使用它。因此,我們將指示它運行命令來代替我們正常的互動式 shell。
用作true
tmux 命令?
因為它退出得非常快並且會使我們的日誌保持簡短。
與 strace 一起使用-o tmux.strace
?
它只是儲存輸出的檔案。要為事物命名是很困難的。將基本名稱或副檔名與其他名稱相符並不重要。
與 strace 一起使用-f
?
我假設您閱讀了手冊頁的摘錄,而不是縮減。任何相當複雜的應用程式都會創建子進程。由於tmux
它非常複雜,我們當然也想追蹤它們。
與 strace 一起使用-s9999
?
由於我們將輸出寫入文件,因此不需要截斷行以適合終端寬度。把它設定大一點。如果出現問題,請稍後處理顯示。
為什麼任何這個?
如果透過任何,你的意思是寫這個長屁股答案......
- 因為我培訓工程團隊並向他們指出這個答案。
- 因為賈爾斯...
- 是個可怕的英雄
- 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
文件的全部內容。