Skip to content

Instantly share code, notes, and snippets.

@Trucido
Created March 3, 2019 03:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trucido/2956fa58b1f5d0bbaef35df3e6442beb to your computer and use it in GitHub Desktop.
Save Trucido/2956fa58b1f5d0bbaef35df3e6442beb to your computer and use it in GitHub Desktop.
if ((! ${+precmd_functions[(r)__vte_osc7|title_precmd]}${+preexec_functions[(r)title_preexec]}))
then
function title {
[[ ( ! -o interactive || $- != *i* ) || $EMACS == *t* ]] && return
emulate -L zsh -o promptsubst -o extendedglob
: ${2=$1}
case ${TERM} in
[aEkx]term*|(#i)rxvt*|(#i)vte*|(#i)cygwin*|(#i)[pk][ui]tty*)
print -Pn "\e]2;$2:q\a"; print -Pn "\e]1;$1:q\a" ;;
screen*)
print -Pn "\ek$1:q\e\\" ;;
*)
zmodload -e zsh/terminfo || zmodload -i zsh/terminfo
if [[ -n ${terminfo[fsl]} && -n ${terminfo[tsl]} ]]; then
echoti tsl; print -Pn "$1"; echoti fsl
fi ;;
esac
}
function title_precmd {
emulate -L zsh
local TIDLE="%15<..<%~%<<"
local WIDLE="%n@%m: %~"
title $TIDLE $WIDLE
}
function title_preexec {
emulate -L zsh -o extendedglob
local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
local LINE="${2:gs/%/%%}"
title '$CMD' '%100>...>$LINE%<<'
}
add-zsh-hook precmd title_precmd
add-zsh-hook preexec title_preexec
fi
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment