Parent directory

screen.plugin.zsh

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