<commit_before>#usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title
#http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
#Fully support screen, iterm, and probably most modern xterm and rxvt
#Limited support for Apple Terminal (Terminal can't set window or tab separately)
function title {
  # split arguments by newlines, then join by spaces:
  1=${(pj: :)${(f)1}}
  2=${(pj: :)${(f)2}}
  # echo "title:1:$1" ; echo "title:2:$2"
  if [[ $TERM == screen* ]]; then 
    local PREFIX SUFFIX RELPWD
    # Get OpenVZ container ID (/proc/bc is only on the host):
    if [[ -r /proc/user_beancounters ]]; then
      if [[ ! -d /proc/bc ]]; then
        # container
        PREFIX="[$(hostname)#$(sed -n 3p /proc/user_beancounters | cut -f1 -d: | tr -d '[:space:]')] "
        SUFFIX=" ($PWD)"
      elif [[ $(pwd -P) == /var/lib/vz/private/[0-9]* ]]; then
        # HN, in container dir
        RELPWD=${$(pwd -P)#/var/lib/vz/private/}
        SUFFIX=" (HN:${RELPWD%%/*}~${RELPWD##[[:digit:]]##/#})"
      fi
    fi
    SUFFIX=${SUFFIX:- ($PWD)}
    print -Pn "\ek$PREFIX$1$SUFFIX\e\\" #set screen hardstatus, usually truncated at 20 chars
  elif [[ ($TERM =~ "^xterm") ]] || [[ ($TERM == "rxvt") ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
    print -Pn "\e]0;$2 (%~)\a" #set window name
    print -Pn "\e]1;$1\a" #set icon (=tab) name (will override window name on broken terminal)
  fi
}

ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
ZSH_THEME_TERM_TITLE_IDLE="%n@%m"

#Appears when you have the prompt
function precmd {
  title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
}

#Appears at the beginning of (and during) of command execution
function preexec {
  local -a typed; typed=(${(z)1}) # split what the user has typed into words using shell parsing
  # Resolve jobspecs, e.g. when "fg" or "%-" is used:<commit_msg>Use $' for quoting to fix "bad substitution" error<commit_after>#usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title
#http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
#Fully support screen, iterm, and probably most modern xterm and rxvt
#Limited support for Apple Terminal (Terminal can't set window or tab separately)
function title {
  # split arguments by newlines, then join by spaces:
  1=${(pj: :)${(f)1}}
  2=${(pj: :)${(f)2}}
  # echo "title:1:$1" ; echo "title:2:$2"
  if [[ $TERM == screen* ]]; then
    local PREFIX SUFFIX RELPWD
    # Get OpenVZ container ID (/proc/bc is only on the host):
    if [[ -r /proc/user_beancounters ]]; then
      if [[ ! -d /proc/bc ]]; then
        # container
        PREFIX="[$(hostname)#$(sed -n 3p /proc/user_beancounters | cut -f1 -d: | tr -d '[:space:]')] "
        SUFFIX=" ($PWD)"
      elif [[ $(pwd -P) == /var/lib/vz/private/[0-9]* ]]; then
        # HN, in container dir
        RELPWD=${$(pwd -P)#/var/lib/vz/private/}
        SUFFIX=" (HN:${RELPWD%%/*}~${RELPWD##[[:digit:]]##/#})"
      fi
    fi
    SUFFIX=${SUFFIX:- ($PWD)}
    print -Pn $'\ek$PREFIX$1$SUFFIX\e\\' #set screen hardstatus, usually truncated at 20 chars
  elif [[ ($TERM =~ "^xterm") ]] || [[ ($TERM == "rxvt") ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
    print -Pn $'\e]0;$2 (%~)\a' #set window name
    print -Pn $'\e]1;$1\a' #set icon (=tab) name (will override window name on broken terminal)
  fi
}

ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
ZSH_THEME_TERM_TITLE_IDLE="%n@%m"

#Appears when you have the prompt
function precmd {
  title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
}

#Appears at the beginning of (and during) of command execution
function preexec {
  local -a typed; typed=(${(z)1}) # split what the user has typed into words using shell parsing
  # Resolve jobspecs, e.g. when "fg" or "%-" is used:
{'fraction_non_alphanumeric': 0.17908496732026144, 'fraction_numerical': 0.013594771241830065, 'mean_word_length': 3.5656324582338903, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '70122', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1462, 'n_words': 398}