1

I have a custom function in my ~/.zshrc file:

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
}

In my ~/.tmux.conf file, I want to do something like this:

set-option -g status-interval 5
set-option -g automatic-rename on
set-option -g automatic-rename-format '#{getCustomWindowName}'

Is there anyway to do this?

Bonus problem: if getCustomWindowName echos nothing (or return 1s), I want it to be the default window name. Is there anyway to do that as well?

2
  • 1
    If I understand what you are trying to accomplish, then I'm thinking that it might be easier to set the title inside the function using tmux rename-window $workspace. Then call that function from inside the zsh prompt (see here). If you want to optimize it, since it is called at each prompt, you could store the previous directory and only call tmux renamew when the directory changes. Mar 31, 2021 at 21:40
  • That worked for my case. Thanks!
    – azizj
    Apr 1, 2021 at 19:20

1 Answer 1

0

I learned from NotTheDr01ds that I could just rename the window from ZSH, so I went with something like this:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .