Zsh: Test title setting termcap properly, reorder truecolor hacks

This commit is contained in:
tastytea 2022-03-27 00:11:34 +01:00
parent c94d93519a
commit 245fba9192
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM

View File

@ -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)