2cd/zsh

使用本工具设置后终端标题失效

123485k opened this issue · 3 comments

如图
本来使用bash的时候终端标题会显示ps1的内容
使用了这个之后就不显示了

2moe commented
  • 编辑 ~/.zshrc
  • 查找 "# THEME"
  • 把加载主题那一行注释掉
  • 编辑 ~/.zshrc
  • 查找 "# THEME"
  • 把加载主题那一行注释掉
    我想要保留主题的情况下,至少终端标题可以显示`username@host:~'这种

找到解决办法了,在~/.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