termsupport.zsh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title
  2. #http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
  3. #Fully support screen, iterm, and probably most modern xterm and rxvt
  4. function title {
  5. if [[ "$DISABLE_AUTO_TITLE" == "true" ]] || [[ "$EMACS" == *term* ]]; then
  6. return
  7. fi
  8. if [[ "$TERM" == screen* ]]; then
  9. print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars
  10. elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ $TERM == ansi ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
  11. print -Pn "\e]2;$2:q\a" #set window name
  12. print -Pn "\e]1;$1:q\a" #set icon (=tab) name
  13. fi
  14. }
  15. ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
  16. ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
  17. # Runs before showing the prompt
  18. function omz_termsupport_precmd {
  19. title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
  20. # Notify Terminal.app of current directory using undocumented OSC sequence
  21. # found in OS X 10.9 and 10.10's /etc/bashrc
  22. if [[ $TERM_PROGRAM == Apple_Terminal ]] && [[ -z $INSIDE_EMACS ]]; then
  23. local PWD_URL="file://$HOSTNAME${PWD// /%20}"
  24. printf '\e]7;%s\a' "$PWD_URL"
  25. fi
  26. }
  27. # Runs before executing the command
  28. function omz_termsupport_preexec {
  29. emulate -L zsh
  30. setopt extended_glob
  31. # cmd name only, or if this is sudo or ssh, the next cmd
  32. local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]:gs/%/%%}
  33. local LINE="${2:gs/%/%%}"
  34. title '$CMD' '%100>...>$LINE%<<'
  35. }
  36. precmd_functions+=(omz_termsupport_precmd)
  37. preexec_functions+=(omz_termsupport_preexec)