Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmux's pane_title doesn't update #1092

Closed
vbauerster opened this issue Nov 6, 2020 · 8 comments
Closed

tmux's pane_title doesn't update #1092

vbauerster opened this issue Nov 6, 2020 · 8 comments

Comments

@vbauerster
Copy link

vbauerster commented Nov 6, 2020

I just switched to powerlevel10k recently and noticed that inside tmux pane titles ceased to update.
I have following tmux setup in order to enable pane title update:

set-option -wg automatic-rename on
set-option -wg automatic-rename-format "#{b:pane_title}"

How it worked before (at least with pure theme):
Enter to tmux session and note PWD, let say it's /home/user/test.
So with aforementioned tmux setup, its pane title should display test. Changing dir up one level with cd .. should change pane title to user. However it doesn't work with powerlevel10k theme.

@romkatv
Copy link
Owner

romkatv commented Nov 6, 2020

Powerlevel10k only sets prompt. It doesn't do anything else. See https://github.com/romkatv/powerlevel10k/blob/master/README.md#which-aspects-of-shell-and-terminal-does-powerlevel10k-affect.

If you want to set terminal title, you need to do it separately.

@vbauerster
Copy link
Author

My point is that this behavior is working for example in pure theme. Do you think pure is doing something to set a tmux's pane title?

@romkatv
Copy link
Owner

romkatv commented Nov 6, 2020

Do you think pure is doing something to set a tmux's pane title?

Yes.

@romkatv
Copy link
Owner

romkatv commented Nov 6, 2020

Try adding this to ~/.zshrc:

# Display $1 in terminal title.
function set-term-title() {
  emulate -L zsh
  if [[ -t 1 ]]; then
    print -rn -- $'\e]0;'${(V)1}$'\a'
  elif [[ -w $TTY ]]; then
    print -rn -- $'\e]0;'${(V)1}$'\a' >$TTY
  fi
}

# When a command is running, display it in the terminal title.
function set-term-title-preexec() {
  if (( P9K_SSH )); then
    set-term-title ${(V%):-"%n@%m: "}$1
  else
    set-term-title $1
  fi
}

# When no command is running, display the current directory in the terminal title.
function set-term-title-precmd() {
  if (( P9K_SSH )); then
    set-term-title ${(V%):-"%n@%m: %~"}
  else
    set-term-title ${(V%):-"%~"}
  fi
}

autoload -Uz add-zsh-hook
add-zsh-hook preexec set-term-title-preexec
add-zsh-hook precmd set-term-title-precmd

Edit: I hereby release this code under the terms of MIT License.

@vbauerster
Copy link
Author

Thank you!

yous added a commit to yous/dotfiles that referenced this issue Nov 13, 2020
@AnimiVulpis
Copy link

@romkatv Is it ok if I use your title setting zsh snippet to write a small plugin for personal use?

I am thinking of using the Blue Oak Model License 1.0.0 for the plugin.

@romkatv
Copy link
Owner

romkatv commented Feb 10, 2021

@romkatv Is it ok if I use your title setting zsh snippet to write a small plugin for personal use?

Sure. I've added a comment stating that the code is available under the terms of MIT License (the same as Powerlevel10k).

I am thinking of using the Blue Oak Model License 1.0.0 for the plugin.

I don't know this license. I cannot tell whether it's compatible with MIT or not.

@AnimiVulpis
Copy link

Thank you very much.

You can find the plugin here.
If there is anything you would like me to improve feel free to open an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants