From 245fba91929c483b890b90135379cc9853f41271 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 27 Mar 2022 00:11:34 +0100 Subject: [PATCH] Zsh: Test title setting termcap properly, reorder truecolor hacks --- .config/zsh/.zshrc | 55 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 1335abb..a9e097c 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -93,31 +93,35 @@ async_init ################################################################################ -case ${TERM} in - (xterm* | tmux* | rxvt* | screen* | alacritty) - # Write some info to terminal title. - # This is seen when the shell prompts for input. - function _my_title_precmd() { - print -Pn "\e]0;%m: %(1j,%j job%(2j|s|); ,)%~\a" - } - add-zsh-hook precmd _my_title_precmd - # Write command and args to terminal title. - # This is seen while the shell waits for a command to complete. - function _my_title_preexec() { - print -Pnv jobs_dir "%(1j,%j job%(2j|s|); ,)%~" - printf "\e]0;%s: %s; %s\a" "${HOST}" "${1}" "${jobs_dir}" - } - add-zsh-hook preexec _my_title_preexec +# Test for the title setting capability (To Status Line) +if tput tsl > /dev/null; then + # Write some info to terminal title. + # This is seen when the shell prompts for input. + function _my_title_precmd() { + print -Pn "\e]0;%m: %(1j,%j job%(2j|s|); ,)%~\a" + } + add-zsh-hook precmd _my_title_precmd + # Write command and args to terminal title. + # This is seen while the shell waits for a command to complete. + function _my_title_preexec() { + print -Pnv jobs_dir "%(1j,%j job%(2j|s|); ,)%~" + printf "\e]0;%s: %s; %s\a" "${HOST}" "${1}" "${jobs_dir}" + } + add-zsh-hook preexec _my_title_preexec +fi - # tmux-direct is available since ncurses-6.2-p20201003. - if [[ "${TERM}" == "tmux-256color" ]] \ - && [[ "${COLORTERM}" == "truecolor" ]]; then - if [[ -f "/usr/share/terminfo/t/tmux-direct" ]]; then - alias $(command -v emacsclient)="TERM=tmux-direct $(command -v emacsclient)" - alias $(command -v emacsremote)="TERM=tmux-direct $(command -v emacsremote)" - fi - fi - ;; +# Translate TrueColor to 256 colors if the terminal doesn't support it +[[ "${COLORTERM}" == *(truecolor|24bit)* ]] || zmodload zsh/nearcolor + +# tmux-direct is available since ncurses-6.2-p20201003 +if [[ "${TERM}" == "tmux-256color" ]] \ + && [[ "${COLORTERM}" == "truecolor" ]] \ + && [[ -f "/usr/share/terminfo/t/tmux-direct" ]]; then + alias $(command -v emacsclient)="TERM=tmux-direct $(command -v emacsclient)" + alias $(command -v emacsremote)="TERM=tmux-direct $(command -v emacsremote)" +fi + +case ${TERM} in (dumb) # Emacs shells and TRAMP. unsetopt ZLE @@ -131,9 +135,6 @@ case ${TERM} in ;; esac -# Translate TrueColor to 256 colors if the terminal doesn't support it -[[ $COLORTERM = *(24bit|truecolor)* ]] || zmodload zsh/nearcolor - # Host specific settings. case $(hostname) in schnibble | gaffer | localhost)