shell - Tmux 将窗口重命名为当前目录

标签 shell tmux

所以我的 .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/

相关文章:

shell - 如何告诉 tmux 在创建新的分离 session 时发出另一个 tmux 命令

tmux - 如何在拖尾日志时清除 tmux 屏幕?

sublimetext2 - subl --wait在tmux中不起作用

tmux - 有没有办法给 tmux 命令起别名?

bash - 如何在 bash 脚本中使用可变参数号?

shell - 如何在makefile中获取shell环境变量?

php - Docker PHP - PECL 安装在使用 Heredoc 和 bash 时无法检测系统类型,但可以使用 SHELL 命令处理 shell 设置

linux - 如何在 linux shell 脚本中比较变量与变量减去常量?

MYSQL 和 Shell 脚本 : Reference individual row attributes from table results?

user-interface - Tmux 和 Vim 的 GUI?