screen.plugin.zsh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # if using GNU screen, let the zsh tell screen what the title and hardstatus
  2. # of the tab window should be.
  3. if [[ "$TERM" == screen* ]]; then
  4. if [[ $_GET_PATH == '' ]]; then
  5. _GET_PATH='echo $PWD | sed "s/^\/Users\//~/;s/^\/home\//~/;s/^~$USER/~/"'
  6. fi
  7. if [[ $_GET_HOST == '' ]]; then
  8. _GET_HOST='echo $HOST | sed "s/\..*//"'
  9. fi
  10. # use the current user as the prefix of the current tab title
  11. TAB_TITLE_PREFIX='"`'$_GET_HOST'`:`'$_GET_PATH' | sed "s:..*/::"`$PROMPT_CHAR"'
  12. # when at the shell prompt, show a truncated version of the current path (with
  13. # standard ~ replacement) as the rest of the title.
  14. TAB_TITLE_PROMPT='$SHELL:t'
  15. # when running a command, show the title of the command as the rest of the
  16. # title (truncate to drop the path to the command)
  17. TAB_TITLE_EXEC='$cmd[1]:t'
  18. # use the current path (with standard ~ replacement) in square brackets as the
  19. # prefix of the tab window hardstatus.
  20. TAB_HARDSTATUS_PREFIX='"[`'$_GET_PATH'`] "'
  21. # when at the shell prompt, use the shell name (truncated to remove the path to
  22. # the shell) as the rest of the title
  23. TAB_HARDSTATUS_PROMPT='$SHELL:t'
  24. # when running a command, show the command name and arguments as the rest of
  25. # the title
  26. TAB_HARDSTATUS_EXEC='$cmd'
  27. # tell GNU screen what the tab window title ($1) and the hardstatus($2) should be
  28. function screen_set()
  29. {
  30. # set the tab window title (%t) for screen
  31. print -nR $'\033k'$1$'\033'\\\
  32. # set hardstatus of tab window (%h) for screen
  33. print -nR $'\033]0;'$2$'\a'
  34. }
  35. # called by zsh before executing a command
  36. function preexec()
  37. {
  38. local -a cmd; cmd=(${(z)1}) # the command string
  39. eval "tab_title=$TAB_TITLE_PREFIX:$TAB_TITLE_EXEC"
  40. eval "tab_hardstatus=$TAB_HARDSTATUS_PREFIX:$TAB_HARDSTATUS_EXEC"
  41. screen_set $tab_title $tab_hardstatus
  42. }
  43. # called by zsh before showing the prompt
  44. function precmd()
  45. {
  46. eval "tab_title=$TAB_TITLE_PREFIX:$TAB_TITLE_PROMPT"
  47. eval "tab_hardstatus=$TAB_HARDSTATUS_PREFIX:$TAB_HARDSTATUS_PROMPT"
  48. screen_set $tab_title $tab_hardstatus
  49. }
  50. fi