我的~/.zshrc
文件中有一个自定义函数:
function getCustomWindowName {
# runs 'sed' on 'pwd' to get special dir name
# and set it to $workspace
if $workspace is valid; then
echo $workspace
return 0
else
echo ""
return 1
fi
}
在我的~/.tmux.conf
档案中,我想做这样的事情:
set-option -g status-interval 5
set-option -g automatic-rename on
set-option -g automatic-rename-format '#{getCustomWindowName}'
有办法做到这一点吗?
额外问题:如果getCustomWindowName
没有回显(或return 1
s),我希望它成为默认窗口名称。无论如何也可以这样做吗?
答案1
我从 NotTheDr01ds 那里了解到我可以从 ZSH 重命名窗口,所以我采用了这样的方法:
function getCustomWindowName {
# runs 'sed' on 'pwd' to get special dir name
# and set it to $workspace
if $workspace is valid; then
tmux rename-window $workspace
fi
}
# only allow unique values in this array
typeset -U chpwd_functions
# run this function when current working directory changes.
# Variables $PWD and $OLDPWD.
chpwd_functions+=(getCustomWindowName)
# Try to update when a new window is opened.
getCustomWindowName