-
Notifications
You must be signed in to change notification settings - Fork 8
/
zshrc
492 lines (424 loc) · 12.2 KB
/
zshrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#
#
# _____
# .'/L|__`.
# / =[_]O|` \
# |"+_____":|
# __:='|____`-:__
# ||[] ||====| []||
# ||[] | |=| | []||
# |:||_|=|U| |_||:|
# |:|||]_=_ =[_||:|
# | |||] [_][]C|| |
# | ||-'"""""`-|| |
# /|\\_\_|_|_/_//|\
# |___| /|\ |___| csexton's zsh config
# `---' |___| `---' Making the Kessel Run in less than twelve parsecs.
# `---'
#
# Colors {{{
autoload -U colors
colors
setopt prompt_subst
# }}}
# Auto Correct {{{
setopt correct_all
# }}}
# Key Bindings {{{
#stty erase ^H &>/dev/null
bindkey "^?" backward-delete-char
bindkey "^[[3~" delete-char
bindkey '^W' vi-backward-kill-word
bindkey -e
bindkey '\ew' kill-region
bindkey -s '\el' "ls\n"
bindkey -s '\e.' "..\n"
bindkey '^r' history-incremental-search-backward
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history
# make search up and down work, so partially type and hit up/down to find relevant stuff
bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search
bindkey "^p" up-line-or-search
bindkey "^n" down-line-or-search
bindkey "^[[H" beginning-of-line
bindkey "^[[1~" beginning-of-line
bindkey "^[OH" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^[[4~" end-of-line
bindkey "^[OF" end-of-line
bindkey ' ' magic-space # also do history expansion on space
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
bindkey '^[[Z' reverse-menu-complete
# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~
bindkey '^?' backward-delete-char
bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
bindkey "\e[3~" delete-char
# stash the current line and run a command, popping it off after
bindkey "^t" push-line-or-edit
# usage: bindtc <cap> <fallback> <zsh-command>
bindtc ()
{
local keyval=$(echotc "$1" 2>&-)
bindkey "${keyval:-$2}" "$3"
}
# Let backtab cycle through completions in reverse
bindtc bt "^[[Z" reverse-menu-complete
# Bindings for PGUP, PGDN, HOME, END
bindtc kP "^[[I" history-beginning-search-backward
bindtc kN "^[[G" history-beginning-search-forward
bindtc kh "^[[H" beginning-of-line
bindtc kH "^[[F" end-of-line
# Bindings for UP, DOWN, LEFT, RIGHT
bindtc ku "^[[A" up-line-or-history
bindtc kd "^[[B" down-line-or-history
bindtc kr "^[[C" forward-char
bindtc kl "^[[D" backward-char
# Emacs style for vi mode
#set -o vi
#bindkey -v # vi mode line editting
#bindkey '^A' beginning-of-line
#bindkey '^E' end-of-line
#bindkey '^K' kill-line
#bindkey '^U' kill-whole-line
#bindkey -M viins '^O' copy-prev-shell-word
#bindkey '^L' push-line # push current command into a buffer, allows you to do another command then returns to previous command
# }}}
# Completion {{{
fpath=(/usr/local/share/zsh-completions $fpath)
fpath=(~/.zsh/completion $fpath)
# Show completion on first TAB
zmodload zsh/complist
autoload -U compinit
compinit
unsetopt menucomplete # do not autoselect the first completion entry
unsetopt flowcontrol
setopt auto_menu # show completion menu on succesive tab press
setopt complete_in_word
setopt always_to_end
#zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX + $#SUFFIX) / 3 )) )'
#zstyle ':completion:*:descriptions' format "- %d -"
#zstyle ':completion:*:corrections' format "- %d - (errors %e})"
#zstyle ':completion:*:default' list-prompt '%S%M matches%s'
#zstyle ':completion:*' group-name ''
#zstyle ':completion:*:manuals' separate-sections true
#zstyle ':completion:*:manuals.(^1*)' insert-sections true
zstyle ':completion:*' menu select
#zstyle ':completion:*' verbose yes
# Case insensitive and substring matching
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# }}}
# History {{{
## Command history configuration
HISTFILE=$HOME/.zsh_history
HISTSIZE=100000
SAVEHIST=100000
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_fcntl_lock
setopt hist_ignore_all_dups
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_no_store
setopt hist_verify
setopt inc_append_history
setopt share_history
alias history='fc -l 1'
# }}}
# Bundler {{{
# The following is based on https://github.com/gma/bundler-exec
alias b="bundle exec"
alias be="bundle exec"
bundled_commands=(
annotate
cap
capify
cucumber
foodcritic
guard
irb
jekyll
kitchen
knife
middleman
nanoc
pry
puma
rackup
rails
rainbows
rake
reek
rspec
rubocop
shotgun
sidekiq
spec
spork
spring
strainer
tailor
taps
thin
thor
unicorn
unicorn_rails
)
# Remove $UNBUNDLED_COMMANDS from the bundled_commands list
for cmd in $UNBUNDLED_COMMANDS; do
bundled_commands=(${bundled_commands#$cmd});
done
# Add $BUNDLED_COMMANDS to the bundled_commands list
for cmd in $BUNDLED_COMMANDS; do
bundled_commands+=($cmd);
done
## Functions
_bundler-installed() {
which bundle > /dev/null 2>&1
}
_within-bundled-project() {
local check_dir="$PWD"
while [ "$check_dir" != "/" ]; do
[ -f "$check_dir/Gemfile" ] && return
check_dir="$(dirname $check_dir)"
done
false
}
_binstubbed() {
[ -f "./bin/${1}" ]
}
_run-with-bundler() {
if _bundler-installed && _within-bundled-project; then
if _binstubbed $1; then
echo "$fg[blue]--> ./bin/$@$reset_color" >&2
./bin/$@
else
echo "$fg[blue]--> bundle exec $@$reset_color" >&2
bundle exec $@
fi
else
echo "$fg[blue]--> $@$reset_color" >&2
$@
fi
}
## Main program
for cmd in $bundled_commands; do
eval "function unbundled_$cmd () { $cmd \$@ }"
eval "function bundled_$cmd () { _run-with-bundler $cmd \$@}"
alias $cmd=bundled_$cmd
if which _$cmd > /dev/null 2>&1; then
compdef _$cmd bundled_$cmd=$cmd
fi
done
#_run-with-bundler() {
# if _bundler-installed && _within-bundled-project; then
# if _binstubbed $1; then
# echo "$fg[blue]--> ./bin/$@$reset_color" >&2
# ./bin/$@
# else
# echo "$fg[blue]--> bundle exec $@$reset_color" >&2
# bundle exec $@
# fi
# else
# $@
# fi
#}
# }}}
# Git {{{
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[red]%}‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[red]%}›%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$reset_color%}%{$fg[yellow]%}∗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_ADDED="%{$reset_color%}%{$fg[green]%}✓%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
# get the name of the branch we are on
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
# Checks if working tree is dirty
parse_git_dirty() {
if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
}
# }}}
# Aliases and Functions {{{
alias rake="noglob bundled_rake" # allows square brackts for rake task invocation
alias heroku="nocorrect heroku" # allows square brackts for rake task invocation
alias ip="curl -s ip.tpo.pe"
ackr() { ack $* app/* lib/* config/* db/migrate/* test/* }
function prompt-dissapoint {
export PROMPT="%{$fg[green]%}ಠ_ಠ %{$reset_color%}"
}
function prompt-ahh {
export PROMPT="%{$fg[green]%}٩◔̯◔۶ %{$reset_color%}"
}
function prompt-roll {
export PROMPT="%{$fg[green]%}◔_◔ %{$reset_color%}"
}
function prompt-yay {
export PROMPT="%{$fg[green]%}(。◕‿◕。) %{$reset_color%}"
}
function prompt-gasp {
export PROMPT="%{$fg[green]%}⊙▃ ⊙ %{$reset_color%}"
}
function prompt-happy {
export PROMPT="%{$fg[green]%}(•‿•) %{$reset_color%}"
}
function prompt-happy-sad {
export PROMPT="%(?,%{$fg[green]%}☺%{$reset_color%},%{$fg[red]%}☹%{$reset_color%}) "
}
function prompt-preso {
export PROMPT="%(?,%{$fg[green]%}◕‿◕%{$reset_color%},%{$fg[red]%}ಠ_ಠ%{$reset_color%}) "
}
function fliptable {
echo "(╯°□°)╯ ┻━┻";
}
# }}}
# Terminal Title {{{
function title {
if [[ "$DISABLE_AUTO_TITLE" == "true" ]] || [[ "$EMACS" == *term* ]]; then
return
fi
if [[ "$TERM" == screen* ]]; then
print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars
elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ $TERM == ansi ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
print -Pn "\e]2;$2:q\a" #set window name
print -Pn "\e]1;$1:q\a" #set icon (=tab) name (will override window name on broken terminal)
fi
}
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
#Appears when you have the prompt
function termsupport_precmd {
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
}
#Appears at the beginning of (and during) of command execution
function termsupport_preexec {
emulate -L zsh
setopt extended_glob
local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
local LINE="${2:gs/$/\\$}"
LINE="${LINE:gs/%/%%}"
title "$CMD" "%100>...>$LINE%<<"
}
autoload -U add-zsh-hook
add-zsh-hook precmd termsupport_precmd
add-zsh-hook preexec termsupport_preexec
# }}}
# Custom Functions {{{
# Kapow {{{
_rack_root_detect(){
setopt chaselinks
local orgdir=$(pwd)
local basedir=$(pwd)
while [[ $basedir != '/' ]]; do
test -e "$basedir/config.ru" && break
builtin cd ".." 2>/dev/null
basedir="$(pwd)"
done
builtin cd $orgdir 2>/dev/null
[[ ${basedir} == "/" ]] && return 1
echo `basename $basedir | sed -E "s/\.(com|net|org)$//"`
}
kapow(){
local vhost=$1
[ ! -n "$vhost" ] && vhost=$(_rack_root_detect)
if [ ! -h ~/.pow/$vhost ]
then
echo "pow: This domain isn’t set up yet. Symlink your application to ${vhost} first."
return 1
fi
[ ! -d ~/.pow/${vhost}/tmp ] && mkdir -p ~/.pow/$vhost/tmp
touch ~/.pow/$vhost/tmp/restart.txt;
if [ $? -eq 0 ]
then
echo " --_--"
echo " ( -_ _)."
echo " ( ~ ) )"
echo " (( ) ( ) () )"
echo " (. )) ( )"
echo ' ``.. ..``'
echo " | |"
echo " (=| |=)"
echo " | | Kapow! Restarted $vhost.dev"
echo ' (../( )\.))'
fi
}
compctl -W ~/.pow -/ kapow
# View the standard out (puts) from any pow app
alias kaput="tail -f ~/Library/Logs/Pow/apps/*"
# Configure a directory for chruby and powrc file
kaboom(){
echo "Creating .powrc file..."
echo "source /opt/homebrew/opt/chruby/share/chruby/chruby.sh" > .powrc
echo "chruby $(cat .ruby-version)" >> .powrc
echo "Symlinking ${PWD##*/} in ~/.pow ..."
ln -si "$PWD" ~/.pow
echo "Done."
}
# }}}
# Edit command line {{{
autoload -U edit-command-line
zle -N edit-command-line
bindkey '\C-x\C-e' edit-command-line
# }}}
# src Command {{{
src(){cd ~/src/$1;}
compctl -W ~/src -/ src
# }}}
# v Command {{{
# Fuzzy file opener in vim
v(){
file=$(fzf)
[[ -n "$file" ]] && $EDITOR $file
}
# }}}
# deriveddata Command {{{
deriveddata(){cd ~/Library/Developer/Xcode/DerivedData/$1;}
compctl -W ~/Library/Developer/Xcode/DerivedData -/ deriveddata
# }}}
# }}}
# Prompt {{{
PROMPT=' %(?::$fg[red]⚠) %{$fg[green]%}%4~ $(git_prompt_info)%{$reset_color%}
%(!.#.⌘) '
#RPROMPT='%{$fg[red]%}$(ruby --version | cut -d' ' -f 1-2)%{$reset_color%}%'
SPROMPT="%{$fg[yellow]%}Correct '%R' to '%r'? %{$fg[blue]%}(Yes, %{$fg_bold[blue]%}No%{$fg_no_bold[blue]%}, Abort, Edit): %{$reset_color%}"
# }}}
# Select the current directory in launchbar, optionally a file
lb () {
if [[ $# = 1 ]]; then
[[ -e "$(pwd)/$1" ]] && open "x-launchbar:select?file=$(pwd)/$1" || open "x-launchbar:select?file=$1"
else
open "x-launchbar:select?file=$(pwd)"
fi
}
f-history() {
print -z $( ([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s --tac | sed 's/ *[0-9]* *//')
}
f-vim() {
local f
local c
f=$(fzf -q "$1")
c="vim $f"
print -s $c
eval $c
}
f-src() {
local dir
dir=$(find ~/src -type d -maxdepth 1 2> /dev/null | fzf +m -q "$1")
cd "$dir"
}
[[ -s /usr/local/etc/profile.d/z.sh ]] && source /usr/local/etc/profile.d/z.sh
# vim: set foldenable fdm=marker fmr={{{,}}}:
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
[ -f "${HOME}/.iterm2_shell_integration.zsh" ] && source "${HOME}/.iterm2_shell_integration.zsh"
# added by travis gem
[ -f /Users/csexton/.travis/travis.sh ] && source /Users/csexton/.travis/travis.sh
# Load the profile if it exists
[[ -s $HOME/.profile ]] && source $HOME/.profile