Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 370 lines (331 sloc) 11.225 kb
88df6f01 »
2011-07-28 Github, whyfor you break multibyte chracter?!
1 # #!/usr/bin/env zsh
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
2 # richo '11
3 #
4 # TODO
5 # Document all of the *TITLE variables
6 # Clean up that infrastructure (honestly, I think I either need to learn zsh
7 # modules, or write a seperate program to do it
75552cae »
2011-08-18 IF that exit code is nonzero, also show it
8 # Update everything to use the COLOR constants instead of escape codes
f7e08100 »
2011-08-18 Refactor colors in zshrc
9 autoload colors
10 colors
1b00edff »
2011-08-19 Add more colors
11 for COLOR in RED BLUE GREEN MAGENTA YELLOW WHITE BLACK CYAN; do
f7e08100 »
2011-08-18 Refactor colors in zshrc
12 eval PR_$COLOR='%{$fg[${(L)COLOR}]%}'
13 eval PR_BRIGHT_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
14 done
15 PR_RESET="%{${reset_color}%}";
16
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
17 source ~/.profile
18 zstyle :compinstall filename '/home/richo/.zshrc'
19 autoload -U compinit promptinit
20 autoload -Uz vcs_info
21 compinit
22
23 promptinit
24 # Lines configured by zsh-newuser-install
25 HISTFILE=~/.histfile
26 HISTSIZE=1000
27 SAVEHIST=1000
28 setopt prompt_subst
29 setopt sharehistory
30
31 function cdp
32 {
33 cd $pdir
34 }
35
82f2c383 »
2011-08-25 collissions avoidance
36 function __richo_host()
45b1ffd4 »
2011-08-18 prompt shows exit status + color
37 {
df75233b »
2011-08-19 Older versions of zsh: ${#?} is always = 0
38 local b=$?
39 local n=$((${#b} + 2))
45b1ffd4 »
2011-08-18 prompt shows exit status + color
40 echo "$sHost[0,-$n]"
41 }
42
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
43 bindkey -v
ffd4c111 »
2011-08-24 Completely refactor prompt generation, zsh handles it all now
44
82f2c383 »
2011-08-25 collissions avoidance
45 PS1="${SHELL_COLOR}%(?.%m.\$(__richo_host) $PR_BRIGHT_RED%?)%b $PR_BRIGHT_BLUE%# "
ffd4c111 »
2011-08-24 Completely refactor prompt generation, zsh handles it all now
46 RPS1="$PR_BRIGHT_BLUE%~ "
47 which rvm-prompt > /dev/null &&
48 RPS1+='$PR_BRIGHT_CYAN($(rvm-prompt v g)) '
49 RPS1+='%b$PR_CYAN$vcs_info_msg_0_$PR_BRIGHT_BLUE${ZSH_TIME}$PR_RESET'
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
50
51 setopt histignoredups
52 bindkey '^R' history-incremental-search-backward
53
54 function _time()
55 {
56 date "+%s"
57 }
58
191627d5 »
2011-07-19 When we create tags automatically, do that in the background
59 function b_tags()
60 {
61 $(cd $1 && ctags -R -f .newtags . 2>/dev/null && mv .newtags tags)
62 }
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
63
b4a072f3 »
2011-08-18 Rename this function to avoid potentiall collisions
64 function __richo_preexec()
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
65 # DOCS
66 # This function has a few variables that it throws around.
67 # I'm thinking pretty seriously about building this show into it's own module and calling that, but load times could become an issue
68 #
69 # reTITLE
70 # -------
71 # This is what the title will be set to after this command finishes
72 #
73 # sTITLE
74 # ------
75 # This is the current value of the title "at rest" (Including things like the prefix)
76 { # {{{ Prexec hax
77 # Potential TODO:
78 # Set a variable for commands where we care about return status
79 # if returnstatus and $! -> Add something to sTITLE
80 reTITLE=$sTITLE
81 case $1 in
82 # Rails kludges
83 "rails "*)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
84 work=`sed -e 's/^rails //' <<< $1`
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
85 case $work in
86 "s"|"server")
87 arg="WEBRICK"
88 ;;
89 esac
90 ;;
6d667a8c »
2011-06-27 Show full command (sans bundle exec) for things I run in the bundle env
91 "bundle exec"*)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
92 arg=`sed -e 's/bundle exec/BE:/' <<< $1`
6d667a8c »
2011-06-27 Show full command (sans bundle exec) for things I run in the bundle env
93 ;;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
94
aa55d823 »
2011-08-18 Move the cd hook in preexec to it's own specific zsh hook
95 "cd"*|"ls"*|"cp"*|"mv"*|"echo"*|"wiki"*|"screen"*|"dig"*|"rm"*|"mkdir"*|"tinfo"*)
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
96 reTITLE=""
97 return ;;
7ad248b7 »
2011-08-05 clear clears title ( Patch from @onlysamurai )
98 "clear"*)
99 arg="zsh";;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
100
101 # If we're doing it to everything, the command is more interesting than
102 # the target
103 *"*")
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
104 arg=$(awk '{print $1}' <<< $1);;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
105 # Catch kill early
106 "kill "*)
107 reTITLE=""
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
108 arg=$(awk '{print $NF}' <<< $1);;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
109 "ctags"*|"killall"*|"screen"*)
110 return ;;
111 "tmux"*)
112 case $rTITLE in
113 *"tmux"*)
114 ;;
115 *)
116 export rTITLE="$rTITLE [tmux]"
106e3ba2 »
2011-08-18 Refactor title functions, again for collisions
117 __set_urxvt_title $rTITLE
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
118 ;;
119 esac
120 ;;
121 "man"*)
122 arg=$1;;
123 "watchr"*)
124 arg="WATCHR";;
125 "./deploy.sh"*)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
126 arg=$(sed $sed_r -e 's/^\.\/deploy.sh/deploy:/' -e 's/114\.111\.139\.//' -e 's|/var/www/||g' <<< $1);;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
127
128 # For Source control I want the whole line, I think...
129 "svn"*|"git"*|"hg"*|"cvs"*)
130 arg=$1;;
131
132 "make"*)
133 arg=$(pwd | grep -o "[^/]*/[^/]*$");;
134
135 # TODO Include host
136 "cap"*)
137 # hax
138 #arg=$(echo $1 | grep -o "(deploy[^ ]*)");;
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
139 arg=$(awk '{print $2}' <<< $1);;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
140 "ncmpc"*)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
141 arg=$(sed $sed_r -e 's/ ?-h */:/' <<< $1);;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
142
143 # Webby stuffs
144 "lynx"*|"links"*)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
145 arg=$(sed $sed_r -e 's/^(lynx|links) (http[s]?:\/\/)?(www\.)?//' -e 's/\/.*$//' <<< $1);;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
146
147 "su"*)
148 arg="!root!"
149 export reTITLE=$sTITLE
150 ;;
151 "ssh"*)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
152 arg=$(awk '{print $NF}' <<< $1)
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
153 # Don't care where in the local fs we are
154 export t_prefix=""
155 export reTITLE=$sTITLE
156 ;;
157 "vim"*)
158 # Vim likes to play funny buggers with my terminal. Show that
159 # bastage who's in charge.
160 export reTITLE=$sTITLE
161 # Don't bother setting a title- handles it.
162 ;;
a64046ca »
2011-08-01 Put thor commands in window title more intelligently
163 "_thor"*|"thor"*)
eedd2264 »
2011-08-01 Added thor titling
164 export reTITLE=$sTITLE
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
165 arg=`sed $sed_r -e 's/^_?thor //' -e 's/ /:/' <<< $1`
eedd2264 »
2011-08-01 Added thor titling
166 if [ -z "$INSCREEN" ]; then
106e3ba2 »
2011-08-18 Refactor title functions, again for collisions
167 __set_urxvt_title "$arg: "
eedd2264 »
2011-08-01 Added thor titling
168 fi
169 ;;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
170 *)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
171 arg=$(awk '{print $NF}' <<< $1);;
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
172 esac
173
106e3ba2 »
2011-08-18 Refactor title functions, again for collisions
174 __set_title $arg
b4a072f3 »
2011-08-18 Rename this function to avoid potentiall collisions
175 }
176 add-zsh-hook preexec __richo_preexec
177 # }}}
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
178
aa55d823 »
2011-08-18 Move the cd hook in preexec to it's own specific zsh hook
179 # {{{ chpwd hook
180 function __richo_chpwd()
181 {
182 # Clear title if we're going home
183 if [ "$PWD" = "$HOME" ]; then
184 export t_prefix=""
185 arg=$sTITLE
186 else
187 if [ -e .title ]; then
188 export pdir=$PWD
189 # XXX Should this happen for all titles?
190 dTITLE=$(cat .title | sed $sed_r 's/[\r\n]//g')
191 export t_prefix="$dTITLE: "
192 arg=""
193 fi
194 if [ -n "$AUTOTAGS" -a -f .autotags ]; then
195 # TODO
196 # Store some more info about the tags, command to run and
197 # git branch, and use the stat time of the file, rather
198 # than the contents to work out timing
199 if [ $((`cat .autotags` + $TAGS_LIFETIME)) -lt `_time` ]; then
200 _time > .autotags
201 echo "Tags are mad old, regenerating."
202 b_tags $PWD &|
203 fi
204 fi
205 fi
106e3ba2 »
2011-08-18 Refactor title functions, again for collisions
206 __set_title $arg
aa55d823 »
2011-08-18 Move the cd hook in preexec to it's own specific zsh hook
207 }
208 add-zsh-hook chpwd __richo_chpwd
209 #}}}
210
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
211 # {{{ Helper functions to set titles
106e3ba2 »
2011-08-18 Refactor title functions, again for collisions
212 function __set_title()
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
213 {
214 if [ ! -z $INSCREEN ] ; then
215 echo -ne "\033k$t_prefix$@\033\\"
216 fi
217 }
106e3ba2 »
2011-08-18 Refactor title functions, again for collisions
218 function __set_urxvt_title()
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
219 {
220 echo -ne "\033]0;$1\007"
221 }
222 # }}}
223 # If we're an ssh connection, just prefix!
487ab656 »
2011-08-24 zsh style conditionals
224 if [[ -n "$SSH_CONNECTION" && "$TERM" =~ "screen" && -z "$TMUX" ]]; then
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
225 export INSCREEN=yes
6fa2574b »
2011-08-19 Localise vars used
226 dTITLE=$sHost
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
227 t_prefix="$dTITLE: "
c7797889 »
2011-08-24 IUpdate to current api
228 __set_title
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
229 fi
230
a44d6a5d »
2011-08-18 Moar collision avoidance
231 function __richo_precmd()
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
232 { # {{{ postexec hax
233 vcs_info 'prompt'
59376bcd »
2011-07-08 Small change, cleanup effort
234 if [ -n "$reTITLE" -a -n "$INSCREEN" ]; then
106e3ba2 »
2011-08-18 Refactor title functions, again for collisions
235 __set_title $reTITLE
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
236 export reTITLE=""
237 fi
a44d6a5d »
2011-08-18 Moar collision avoidance
238 }
239 add-zsh-hook precmd __richo_precmd
240 # }}}
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
241
242 # TODO This is just someone's template, fix.
243 # set formats
244 # %b - branchname
245 # %u - unstagedstr (see below)
246 # %c - stangedstr (see below)
247 # %a - action (e.g. rebase-i)
248 # %R - repository path
249 # %S - path in the repository
250 REPO_COLOR=${PR_CYAN}
251 # ^^ HAX?
252 # # e.g. master¹²
253 FMT_ACTION="(${PR_CYAN}%a${PR_RESET}%)" # e.g. (rebase-i)
254
255 # check-for-changes can be really slow.
256 # you should disable it, if you work with large repositories
257 zstyle ':vcs_info:*' enable hg git bzr svn
258 zstyle ':vcs_info:*:prompt:*' check-for-changes true
259 if [ -n "$BROKEN_MULTIBYTE" ]; then
88df6f01 »
2011-07-28 Github, whyfor you break multibyte chracter?!
260 zstyle ':vcs_info:*:prompt:*' unstagedstr '¹' # display ¹ if there are unstaged changes
261 zstyle ':vcs_info:*:prompt:*' stagedstr '²' # display ² if there are staged changes
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
262 else
88df6f01 »
2011-07-28 Github, whyfor you break multibyte chracter?!
263 zstyle ':vcs_info:*:prompt:*' unstagedstr '¹' # display ¹ if there are unstaged changes
264 zstyle ':vcs_info:*:prompt:*' stagedstr '²' # display ² if there are staged changes
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
265 fi
266 # Save this for later ³
267 # TODO - Show something if I have unpushed changes.
268 function _init(){
269 FMT_BRANCH="${REPO_COLOR}%b${PR_BRIGHT_CYAN}%u%c${PR_RESET}${PR_RED}%m${PR_RESET}"
270 zstyle ':vcs_info:*:prompt:*' actionformats "${FMT_BRANCH}${FMT_ACTION}"
271 zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}"
272 zstyle ':vcs_info:*:prompt:*' nvcsformats "" "%~"
273 }
274 function svn_init(){
275 SVN_BRANCH="${REPO_COLOR}%b${PR_BRIGHT_CYAN}%u%c${PR_RESET}${PR_RED}%m${PR_RESET}"
276 zstyle ':vcs_info:svn:prompt:*' actionformats "${SVN_BRANCH}${FMT_ACTION}"
277 zstyle ':vcs_info:svn:prompt:*' formats "${SVN_BRANCH}"
278 }
279 _init
280
281 # Show remote ref name and number of commits ahead-of or behind
cd3dbb90 »
2011-06-24 Clean up the git hook a bit further
282 countl () { wc -l | sed $sed_r -e "s/^ +//" }
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
283 function +vi-git-st() { #{{{
284 local ahead remote msg origin
285 local -a gitstatus
286
287 # Are we on a remote-tracking branch?
288 remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
289 --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
290
291 msg=""
292
293 if [[ -n ${remote} ]] ; then
294 # for git prior to 1.7
295 # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
cd3dbb90 »
2011-06-24 Clean up the git hook a bit further
296 origin=$(git rev-list origin/${hook_com[branch]}..HEAD 2>/dev/null | countl)
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
297 (( $origin )) && msg+="+$origin"
298
cd3dbb90 »
2011-06-24 Clean up the git hook a bit further
299 ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | countl)
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
300 (( $ahead )) && msg+="|$ahead|"
301
cd3dbb90 »
2011-06-24 Clean up the git hook a bit further
302 behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | countl)
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
303 (( $behind )) && msg+="-$behind"
304
cd3dbb90 »
2011-06-24 Clean up the git hook a bit further
305 stashes=$(git stash list 2>/dev/null | countl)
302cbfa1 »
2011-06-22 Fixed some broken regexes
306 if [ "$stashes" -gt 0 ]; then
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
307 msg+="?${stashes}s"
308 fi
309
310 #(( $ahead )) && hook_com[misc]+=" (+$ahead)"
311 [ -n "$msg" ] && hook_com[misc]=" ($msg)"
312 fi
313 } #}}}
314 function +vi-svn-nochanges() { #{{{
315 REPO_COLOR="${PR_YELLOW}"
316 svn_init
317 zstyle ':vcs_info:svn*+set-message:*' hooks ""
318 } #}}}
319 function +vi-svn-untimeduncommitted() { #{{{
320 v=$(svnversion)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
321 if grep "M$" > /dev/null 2>&1 <<< $v; then
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
322 hook_com[misc]="**"
323 fi
324 } #}}}
325
326 function +vi-svn-uncommitted() { #{{{
6fa2574b »
2011-08-19 Localise vars used
327 local v=$(timeout $SVNVERSION_TIMEOUT svnversion)
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
328 case $? in
329 124)
330 +vi-svn-nochanges
331 ;;
332 0)
2405e5c3 »
2011-08-06 Use shell redirection instead of echo
333 if grep "M$" > /dev/null 2>&1 <<< $v; then
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
334 hook_com[misc]="**"
335 fi
336 ;;
337 esac
338 } #}}}
339
340 zstyle ':vcs_info:git*+set-message:*' hooks git-st
341 if which timeout >/dev/null; then
342 zstyle ':vcs_info:svn*+set-message:*' hooks svn-uncommitted
343 else
344 zstyle ':vcs_info:svn*+set-message:*' hooks svn-untimeduncommitted
345 fi
346
347 alias nochanges="zstyle ':vcs_info:svn*+set-message:*' hooks svn-nochanges"
348 alias changes="zstyle ':vcs_info:svn*+set-message:*' hooks svn-untimeduncommitted"
349
350 # FIXME!!!
f8f3fa94 »
2011-06-24 Now uses .svnignore and .gitignore to work out what not to commit
351 # This is horrid, and I'm clearly knackered. There /is/ an easier way to
352 # replace the newlines with pipe symbols. There is.
fc2ee171 »
2011-06-28 Only create these zstyle elements if the source files exist
353 [ -e ~/.gitignore ] &&
354 zstyle ':completion:*:*:git-add:*' ignored-patterns `grep -v "^#" ~/.gitignore | xargs echo | sed -e 's/ /|/g'`
355 [ -e ~/.subversion/config ] &&
f0636b93 »
2011-07-06 Remogved an extra xargs
356 zstyle ':completion:*:*:svn-add:*' ignored-patterns `grep "^global-ignores" ~/.subversion/config | sed -e 's/^.*= //' -e 's/ /|/g'`
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
357
358 zstyle ':completion:*:functions' ignored-patterns '_*'
359 zstyle ':completion:*:*:kill:*' menu yes select
360 zstyle ':completion:*:kill:*' force-list always
361 # If we're spawning a shell in a urxvt, but we're NOT in shell, put the tty in
362 # the titlebar.
ec0a6153 »
2011-07-29 Clean up a test
363 if [[ "$TERM" =~ "-256color" && -z "$INSCREEN" ]]; then
106e3ba2 »
2011-08-18 Refactor title functions, again for collisions
364 __set_urxvt_title $rTITLE
aef0fc6e »
2011-06-21 A few files I've quickly checked for sanity
365 fi
366
367
fe60a366 »
2011-06-28 Allow for .hostname instead of .local
368 [ -e $HOME/.zshrc.$sHost ] && source $HOME/.zshrc.$sHost
49da8fba »
2011-08-15 Experimenting with tmuxinator
369 [[ -s $HOME/.tmuxinator/scripts/tmuxinator ]] && source $HOME/.tmuxinator/scripts/tmuxinator
Something went wrong with that request. Please try again.