Browse code

Merge pull request #706 from docwhat/termsupport-hook

lib/termsupport now uses add-zsh-hook

Robby Russell authored on 15/12/2011 at 05:52:42
Showing 4 changed files
... ...
@@ -4,7 +4,7 @@
4 4
 #Limited support for Apple Terminal (Terminal can't set window or tab separately)
5 5
 function title {
6 6
   [ "$DISABLE_AUTO_TITLE" != "true" ] || return
7
-  if [[ "$TERM" == screen* ]]; then 
7
+  if [[ "$TERM" == screen* ]]; then
8 8
     print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars
9 9
   elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
10 10
     print -Pn "\e]2;$2:q\a" #set window name
... ...
@@ -16,14 +16,18 @@ ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
16 16
 ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
17 17
 
18 18
 #Appears when you have the prompt
19
-function precmd {
19
+function omz_termsupport_precmd {
20 20
   title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
21 21
 }
22 22
 
23 23
 #Appears at the beginning of (and during) of command execution
24
-function preexec {
24
+function omz_termsupport_preexec {
25 25
   emulate -L zsh
26 26
   setopt extended_glob
27 27
   local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
28 28
   title "$CMD" "%100>...>$2%<<"
29 29
 }
30
+
31
+autoload -U add-zsh-hook
32
+add-zsh-hook precmd  omz_termsupport_precmd
33
+add-zsh-hook preexec omz_termsupport_preexec
... ...
@@ -2,7 +2,7 @@ function toon {
2 2
   echo -n ""
3 3
 }
4 4
 
5
-get_git_dirty() { 
5
+get_git_dirty() {
6 6
   git diff --quiet || echo '*'
7 7
 }
8 8
 
... ...
@@ -18,9 +18,12 @@ zstyle ':vcs_info:*' formats       \
18 18
 zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
19 19
 zstyle ':vcs_info:*' enable git cvs svn
20 20
 
21
-precmd () {
21
+theme_precmd () {
22 22
     vcs_info
23 23
 }
24 24
 
25 25
 setopt prompt_subst
26 26
 PROMPT='%{$fg[magenta]%}$(toon)%{$reset_color%} %~/ %{$reset_color%}${vcs_info_msg_0_}%{$reset_color%}'
27
+
28
+autoload -U add-zsh-hook
29
+add-zsh-hook precmd theme_precmd
27 30
\ No newline at end of file
... ...
@@ -1,19 +1,19 @@
1
-function precmd {
1
+function theme_precmd {
2 2
     local TERMWIDTH
3 3
     (( TERMWIDTH = ${COLUMNS} - 1 ))
4 4
 
5 5
 
6 6
     ###
7 7
     # Truncate the path if it's too long.
8
-    
8
+
9 9
     PR_FILLBAR=""
10 10
     PR_PWDLEN=""
11
-    
11
+
12 12
     local promptsize=${#${(%):---(%n@%m:%l)---()--}}
13 13
     local rubyprompt=`rvm_prompt_info`
14 14
     local rubypromptsize=${#${rubyprompt}}
15 15
     local pwdsize=${#${(%):-%~}}
16
-    
16
+
17 17
     if [[ "$promptsize + $rubypromptsize + $pwdsize" -gt $TERMWIDTH ]]; then
18 18
       ((PR_PWDLEN=$TERMWIDTH - $promptsize))
19 19
     else
... ...
@@ -24,7 +24,7 @@ function precmd {
24 24
 
25 25
 
26 26
 setopt extended_glob
27
-preexec () {
27
+theme_preexec () {
28 28
     if [[ "$TERM" == "screen" ]]; then
29 29
 	local CMD=${1[(wr)^(*=*|sudo|-*)]}
30 30
 	echo -n "\ek$CMD\e\\"
... ...
@@ -69,7 +69,7 @@ setprompt () {
69 69
 
70 70
     ###
71 71
     # See if we can use extended characters to look nicer.
72
-    
72
+
73 73
     typeset -A altchar
74 74
     set -A altchar ${(s..)terminfo[acsc]}
75 75
     PR_SET_CHARSET="%{$terminfo[enacs]%}"
... ...
@@ -81,10 +81,10 @@ setprompt () {
81 81
     PR_LRCORNER=${altchar[j]:--}
82 82
     PR_URCORNER=${altchar[k]:--}
83 83
 
84
-    
84
+
85 85
     ###
86 86
     # Decide if we need to set titlebar text.
87
-    
87
+
88 88
     case $TERM in
89 89
 	xterm*)
90 90
 	    PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
... ...
@@ -96,8 +96,8 @@ setprompt () {
96 96
 	    PR_TITLEBAR=''
97 97
 	    ;;
98 98
     esac
99
-    
100
-    
99
+
100
+
101 101
     ###
102 102
     # Decide whether to set a screen title
103 103
     if [[ "$TERM" == "screen" ]]; then
... ...
@@ -105,8 +105,8 @@ setprompt () {
105 105
     else
106 106
 	PR_STITLE=''
107 107
     fi
108
-    
109
-    
108
+
109
+
110 110
     ###
111 111
     # Finally, the prompt.
112 112
 
... ...
@@ -135,3 +135,7 @@ $PR_CYAN$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '
135 135
 }
136 136
 
137 137
 setprompt
138
+
139
+autoload -U add-zsh-hook
140
+add-zsh-hook precmd  theme_precmd
141
+add-zsh-hook preexec theme_preexec
138 142
\ No newline at end of file
... ...
@@ -7,7 +7,7 @@ zstyle ':vcs_info:*' unstagedstr '%F{yellow}●'
7 7
 zstyle ':vcs_info:*' check-for-changes true
8 8
 zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{11}%r'
9 9
 zstyle ':vcs_info:*' enable git svn
10
-precmd () {
10
+theme_precmd () {
11 11
     if [[ -z $(git ls-files --other --exclude-standard 2> /dev/null) ]] {
12 12
         zstyle ':vcs_info:*' formats ' [%b%c%u%B%F{green}]'
13 13
     } else {
... ...
@@ -19,3 +19,6 @@ precmd () {
19 19
 
20 20
 setopt prompt_subst
21 21
 PROMPT='%B%F{magenta}%c%B%F{green}${vcs_info_msg_0_}%B%F{magenta} %{$reset_color%}%% '
22
+
23
+autoload -U add-zsh-hook
24
+add-zsh-hook precmd  theme_precmd