Zsh

基於 ZSH 中的自定義函式重命名 TMUX 視窗

  • April 2, 2021

我的~/.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 1s),我希望它是預設的視窗名稱。無論如何也可以這樣做嗎?

我從 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

引用自:https://unix.stackexchange.com/questions/642941