feat (zsh/term_title): add support for displaying terminal titles in a nice way
This commit is contained in:
parent
9713982a79
commit
50d50ff069
43
zsh/term_title
Normal file
43
zsh/term_title
Normal file
@ -0,0 +1,43 @@
|
||||
set_termtitle() {
|
||||
# escape '%' chars in "${1}", make nonprintables visible
|
||||
local a="${(V)1//\%/\%\%}"
|
||||
|
||||
# Truncate command, and join lines.
|
||||
a="${a//[$'\r'$'\n']/}"
|
||||
|
||||
[[ "${a}" = "zsh" ]] && { a="${(%)${:-%~}}" }
|
||||
|
||||
case "${TERM}" in
|
||||
screen)
|
||||
# plain xterm title
|
||||
print -rn -- $'\e'"]2;${(%)${:-%m}}: ${a}"$'\a'
|
||||
|
||||
# screen title (in ^A")
|
||||
print -rn -- $'\e'"k${a}"$'\e'$'\\'
|
||||
|
||||
# screen location
|
||||
print -rn -- $'\e'"_${(%)${:-%m}}: ${a}"$'\e'$'\\'
|
||||
;;
|
||||
xterm*|rxvt*)
|
||||
# plain xterm title
|
||||
print -rn -- $'\e'"]2;${(%)${:-%m}}: ${a}"$'\a'
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
my_prompt_precmd() {
|
||||
set_termtitle "zsh"
|
||||
}
|
||||
|
||||
my_prompt_preexec() {
|
||||
set_termtitle "${1}"
|
||||
}
|
||||
|
||||
typeset -ga precmd_functions
|
||||
precmd_functions+=my_prompt_precmd
|
||||
|
||||
typeset -ga preexec_functions
|
||||
preexec_functions+=my_prompt_preexec
|
||||
|
Loading…
Reference in New Issue
Block a user