所以我的 .zshrc
中有这个函数,可以将当前的 tmux 窗口重命名为当前目录。
precmd () {
tmux set-window-option -qg window-status-format "#[fg=colour18 bg=colour18] | #[fg=white, bg=colour18] #I | ${PWD##/*/} #[fg=colour18, bg=colour18] | "
tmux set-window-option -qg window-status-current-format "#[fg=colour18, bg=blue] | #[fg=white, bg=blue] #I | ${PWD##/*/} #[fg=blue, bg=colour18] | "
}
这工作正常,但我想知道为什么相同的代码在我的 .tmux.conf
# Status Bar
set-window-option -qg window-status-format "#[fg=colour18 bg=colour18] | #[fg=white, bg=colour18] #I | ${PWD##/*/} #[fg=colour18, bg=colour18] | "
set-window-option -qg window-status-current-format "#[fg=colour18, bg=blue] | #[fg=white, bg=blue] #I | ${PWD##/*/} #[fg=blue, bg=colour18] | "
如果我尝试使用此功能,则在启动 tmux 时会收到错误消息。
这有什么原因吗?我可以使用 #{pane_current_path}"
获得相同的效果并将路径缩短为当前目录吗?
最佳答案
我认为它不起作用,因为该函数是在创建 tty 之前执行的。它与 shell 函数一起工作,因为你在 tmux 完全启动后执行它。但是.tmux.conf
是在tmux启动的时候执行的。
所以我会把它保存在您的 .zshrc
中,可能会立即执行该函数。
关于shell - Tmux 将窗口重命名为当前目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29723307/