-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathzshrc
782 lines (576 loc) · 24.6 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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
# Sourced in interactive shells
##############################################################################
# PATH stuff
##############################################################################
# Setup PATH for interactive shell
if [[ -d "${HOME}/.rbenv/bin" ]]
then
PATH="${HOME}/.rbenv/bin:${PATH}"
fi
for p in '/usr/local/sbin' '/usr/sbin' '/sbin' '/bin' '/usr/bin' '/usr/local/bin' "${HOME}/bin"
do
PATH="${p}:${PATH}"
done
# Pick up go binaries
if (($+GOPATH))
then
PATH="${PATH}:${GOPATH}/bin"
fi
# Pick up NPM-installed binaries
if [[ -d "/usr/local/share/npm/bin" ]]
then
PATH="${PATH}:/usr/local/share/npm/bin"
fi
# If we're on OS X, we want access to the `stroke` utility
if [[ -d "/Applications/Utilities/Network Utility.app/Contents/Resources" ]]
then
PATH="${PATH}:/Applications/Utilities/Network Utility.app/Contents/Resources"
fi
# If we're on OS X, we want access to the `airport` utility
if [[ -d "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources" ]]
then
PATH="${PATH}:/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources"
fi
# Deduplicate entries in PATH
typeset -U PATH
export PATH
##############################################################################
# Keybindings
##############################################################################
## keybindings (run 'bindkeys' for details, more details via man zshzle)
# use emacs style per default:
bindkey -e
# use vi style:
# bindkey -v
# Map jj to ESC, just like in Vim
# bindkey -M viins 'jj' vi-cmd-mode
# Enable Ctrl-R to do backwards history search
# bindkey '^R' history-incremental-search-backward
# vi mode
# bindkey -v
# bindkey "^F" vi-cmd-mode
# bindkey jj vi-cmd-mode
# handy keybindings
bindkey "^A" beginning-of-line
bindkey "^E" end-of-line
bindkey "^R" history-incremental-search-backward
bindkey "^P" history-search-backward
bindkey "^Y" accept-and-hold
bindkey "^N" insert-last-word
bindkey -s "^T" "^[Isudo ^[A" # "t" for "toughguy"
# Enable Ctrl-x-e to edit command line
autoload -U edit-command-line
# Emacs style
zle -N edit-command-line
bindkey '^xe' edit-command-line
bindkey '^x^e' edit-command-line
# Vi style:
# zle -N edit-command-line
# bindkey -M vicmd v edit-command-line
##############################################################################
# Completions
##############################################################################
fpath=(~/.zsh/completion ~/.zsh/functions /usr/local/share/zsh/site-functions $fpath)
typeset -U fpath # Remove duplicates from $fpath
## completions ####
autoload -U compinit
compinit
autoload -U zstyle+
# Try to correct command line spelling
# setopt correct correctall
setopt correct
## General completion technique
## complete as much as you can ..
zstyle ':completion:*' completer _complete _list _oldlist _expand _ignored _match _correct _approximate _prefix
## complete less
#zstyle ':completion:*' completer _expand _complete _list _ignored _approximate
## complete minimal
#zstyle ':completion:*' completer _complete _ignored
## determine in which order the names (files) should be
## listed and completed when using menu completion.
## `size' to sort them by the size of the file
## `links' to sort them by the number of links to the file
## `modification' or `time' or `date' to sort them by the last modification time
## `access' to sort them by the last access time
## `inode' or `change' to sort them by the last inode change time
## `reverse' to sort in decreasing order
## If the style is set to any other value, or is unset, files will be
## sorted alphabetically by name.
zstyle ':completion:*' file-sort name
## case-insensitive (uppercase from lowercase) completion
#zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
## case-insensitive (all) completion
#zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
## case-insensitive,partial-word and then substring completion
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
## completion caching
zstyle ':completion:*' use-cache on
# zstyle ':completion:*' cache-path ~/.zcompcache/$HOST
## add colors to completions
zstyle ':completion:*' list-colors ${(s.:.)LSCOLORS}
### If you want zsh's completion to pick up new commands in $path automatically
### comment out the next line and un-comment the following 5 lines
zstyle ':completion:::::' completer _complete _approximate
#_force_rehash() {
# (( CURRENT == 1 )) && rehash
# return 1# Because we didn't really complete anything
#}
#zstyle ':completion:::::' completer _force_rehash _complete _approximate
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
zstyle ':completion:*:kill:*:processes' command "ps x"
# Auto-completion for ssh hosts
zstyle -e ':completion::*:hosts' hosts 'reply=($(sed -e "/^#/d" -e "s/ .*\$//" -e "s/,/ /g" /etc/ssh_known_hosts(N) ~/.ssh/known_hosts(N) 2>/dev/null | xargs) $(grep \^Host ~/.ssh/config(N) | cut -f2 -d\ 2>/dev/null | xargs))'
# cd will never select the parent directory (e.g.: cd ../<TAB>):
# zstyle ':completion:*:cd:*' ignore-parents parent pwd
# Fuzzy matching of completions for when you mistype them:
# zstyle ':completion:*' completer _complete _match _approximate
# zstyle ':completion:*:match:*' original only
# zstyle ':completion:*:approximate:*' max-errors 1 numeric
##############################################################################
# Colors
##############################################################################
autoload -U colors; colors;
# Allow functions in (R)PROMPT
setopt prompt_subst
# Combined left and right prompt configuration.
local smiley="%(?,%F{green}😊%f,%F{red}☹%f)"
PROMPT='%m %B%F{red}:: %F{green}%3~ ${smiley} %F{blue}%(0!.#.») %b%f'
RPROMPT=''
if type pretty-git-prompt > /dev/null; then
RPROMPT="\$(pretty-git-prompt) $RPROMPT"
fi
# Put rbenv version info on the right side, if rbenv is available
if type rbenv > /dev/null; then
RPROMPT="%F{white}\$(rbenv version-name)%f $RPROMPT";
fi
# TODO LSCOLORS and LS_COLORS don't define the same color scheme
# This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color.
# The order of the attributes are as follows:
# 1. directory
# 2. symbolic link
# 3. socket
# 4. pipe
# 5. executable
# 6. block special
# 7. character special
# 8. executable with setuid bit set
# 9. executable with setgid bit set
# 10. directory writable to others, with sticky bit
# 11. directory writable to others, without sticky bit
export LSCOLORS="gxfxcxdxbxegedabagacad"
# GNU ls uses LS_COLORS:
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'
##############################################################################
# System limits
##############################################################################
# ulimit -n 1024
##############################################################################
# Zsh options & plugins
##############################################################################
autoload -U zmv
autoload -U history-search-end
# Report CPU usage for commands running longer than 10 seconds
REPORTTIME=10
# history:
setopt inc_append_history # append history list to the history file (important for multiple parallel zsh sessions!)
setopt share_history # import new commands from the history file also in other zsh-session
setopt extended_history # save each command's beginning timestamp and the duration to the history file
setopt hist_ignore_all_dups # If a new command line being added to the history list duplicates an older one, the older command is removed from the list
setopt hist_ignore_space # remove command lines from the history list when the first character on the line is a space
HISTFILE=$HOME/.zsh_history
HISTSIZE=10000000
SAVEHIST=10000000 # useful for setopt append_history
setopt auto_cd # if a command is issued that can't be executed as a normal command,
# and the command is the name of a directory, perform the cd command to that directory
setopt extended_glob # in order to use #, ~ and ^ for filename generation
# grep word *~(*.gz|*.bz|*.bz2|*.zip|*.Z) ->
# -> searches for word not in compressed files
# don't forget to quote '^', '~' and '#'!
setopt notify # report the status of backgrounds jobs immediately
setopt hash_list_all # Whenever a command completion is attempted, make sure
# the entire command path is hashed first.
# setopt completeinword # not just at the end
setopt nohup # Don't kill background jobs when shell exits
# setopt auto_pushd # make cd push the old directory onto the directory stack.
setopt nonomatch # try to avoid the 'zsh: no matches found...'
setopt nobeep # avoid "beep"ing
setopt pushd_ignore_dups # don't push the same dir twice.
setopt noglobdots # * shouldn't match dotfiles. ever.
setopt long_list_jobs # List jobs in long format, display PID when suspending processes as well
setopt mark_dirs # Append a trailing `/' to all directory names resulting from globbing
##############################################################################
# Custom aliases
##############################################################################
# alias -s rb="${EDITOR}"
# alias -s tex="${EDITOR}"
# alias -s html=w3m
# alias -s org=w3m
# alias -g ...='../..'
# alias -g ....='../../..'
# alias -g .....='../../../..'
# alias -g CA="2>&1 | cat -A"
# alias -g C='| wc -l'
# alias -g D="DISPLAY=:0.0"
# alias -g DN=/dev/null
# alias -g ED="export DISPLAY=:0.0"
# alias -g EG='|& egrep'
# alias -g EH='|& head'
# alias -g EL='|& less'
# alias -g ELS='|& less -S'
# alias -g ETL='|& tail -20'
# alias -g ET='|& tail'
# alias -g F=' | fmt -'
# alias -g G='| egrep'
# alias -g H='| head'
# alias -g HL='|& head -20'
# alias -g Sk="*~(*.bz2|*.gz|*.tgz|*.zip|*.z)"
# alias -g LL="2>&1 | less"
# alias -g L="| less"
# alias -g LS='| less -S'
# alias -g MM='| most'
# alias -g M='| more'
# alias -g NE="2> /dev/null"
# alias -g NS='| sort -n'
# alias -g NUL="> /dev/null 2>&1"
# alias -g PIPE='|'
# alias -g R=' > /c/aaa/tee.txt '
# alias -g RNS='| sort -nr'
# alias -g S='| sort'
# alias -g TL='| tail -20'
# alias -g T='| tail'
# alias -g US='| sort -u'
# alias -g VM=/var/log/messages
# alias -g X0G='| xargs -0 egrep'
# alias -g X0='| xargs -0'
# alias -g XG='| xargs egrep'
# alias -g X='| xargs'
# do we have GNU ls with color-support?
if $(gls &>/dev/null)
then
alias ls='gls -F --color'
alias la='gls -FA --color'
alias ll='gls -lh --color'
alias lh='gls -lhA --color'
alias l='gls -lhF --color'
else
alias ls='ls -bh -CF'
alias la='ls -lhAF'
alias ll='ls -lh'
alias lh='ls -hAl'
alias l='ls -lhF'
fi
# Suffix-based aliases, eg `user.rb` will invoke emacsclient on that file
# alias -s rb=e
# grep marius /etc/passwd C
# expands to grep marius /etc/passwd | wc -l
# alias -g C='| wc -l'
alias '..'='cd ..'
# The -g makes them global aliases, so they're expaned even inside commands
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
# Aliases '-' to 'cd -'
alias -- -='cd -'
alias cp='nocorrect cp' # no spelling correction on cp
alias mkdir='nocorrect mkdir' # no spelling correction on mkdir
alias mv='nocorrect mv' # no spelling correction on mv
alias rm='nocorrect rm' # no spelling correction on rm
# Execute rmdir
alias rd='rmdir'
# Execute rmdir
alias md='mkdir -p'
# general
# Execute du -sch
alias da='du -sch'
# Execute jobs -l
alias j='jobs -l'
# chmod
alias rw-='chmod 600'
alias rwx='chmod 700'
alias r--='chmod 644'
alias r-x='chmod 755'
alias tlf="tail -f"
alias fuck='sudo $(history -p \!\!)'
#########################################################################################
# Custom aliases/commands
# Use Ctrl-Z to switch back to vim too!
# Nicked from https://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
alias computer,="sudo"
alias such=git
alias very=git
alias wow='git status --branch --short'
# Convert a picture to a favicon
alias make-favicon="convert -colors 256 -resize 16x16 "
# Copy the working dir to the clipboard
alias cpwd='pwd|xargs echo -n|pbcopy'
# Show current airport status:
alias apinfo='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I'
alias httpdump='sudo tcpdump -i en0 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"'
# mkdir, cd into it (via http://onethingwell.org/post/586977440/mkcd-improved)
function mkcd () {
mkdir -p "$*"
cd "$*"
}
alias ydl=youtube-dl
# If bcat (Browser cat, http://rtomayko.github.com/bcat/) is invoked as `btee', it acts like `tee(1)'
alias btee=bcat
# sh function to murder all running processes matching a pattern
# thanks 3n: http://twitter.com/3n/status/19113206105
function murder () {
ps | grep $1 | grep -v grep | awk '{print $1}' | xargs kill -9
}
alias dotedit="$VISUAL ~/dotfiles/"
alias homegit="GIT_DIR=~/dotfiles/.git GIT_WORK_TREE=~ git"
alias sha1='openssl dgst -sha1'
alias sha256='openssl dgst -sha256'
alias wk2png='/usr/bin/python $(which webkit2png)'
function console {
if [[ $# > 0 ]]; then
query=$(echo "$*" | tr -s ' ' '|')
tail -f /var/log/system.log|grep -i --color=auto -E "$query"
else
tail -f /var/log/system.log
fi
}
function backup-itunes() {
printf "Backing up Music and Audiobooks\n"
rsync --update --human-readable --recursive --progress --inplace --8-bit-output ~/Music/iTunes/iTunes\ Music/{Music,Audiobooks} "${ITUNES_BACKUP_DIR}";
printf "Backing up iOS Apps\n"
rsync --update --human-readable --recursive --progress --inplace --8-bit-output --delete-after ~/Music/iTunes/iTunes\ Music/Mobile\ Applications "${ITUNES_BACKUP_DIR}";
}
alias pg_start='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start'
alias pg_stop='pg_ctl -D /usr/local/var/postgres stop -s -m fast'
alias flush-dns-cache='sudo killall -HUP mDNSResponder'
# Quick way to rebuild the Launch Services database and get rid of duplicates in the Open With submenu.
# via https://sixcolors.com/post/2015/10/clean-out-a-messy-open-with-menu-in-the-finder/
alias reubild-launch-serivces-db='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user'
alias now='ruby -e "puts Time.now.utc.to_i"'
alias uuid='python -c "import uuid; print uuid.uuid1()"'
# Based on http://schneems.com/post/41104255619/use-gifs-in-your-pull-request-for-good-not-evil
function convert-video-to-gif() {
TMPFILE=$(mktemp -t gifvideo)
echo "TMPFILE is $TMPFILE"
echo "Converting..."
ffmpeg -y -i "$1" -pix_fmt rgb24 -f gif "$TMPFILE"
echo "Optimizing..."
convert -verbose -layers Optimize "$TMPFILE" "$2"
rm -f "$TMPFILE"
}
# 'work on', via https://coderwall.com/p/feoi0a
function wo() {
cd $(find $CODE_DIR -type d -maxdepth 3 | grep -i $* | grep -Ev Pods --max-count=1)
}
function dash() {
open "dash://$1"
}
# `wifi on` to turn wifi on, and `wifi off` to turn it off
alias wifi="networksetup -setairportpower $(networksetup -listallhardwareports | grep -A 2 'Hardware Port: Wi-Fi' | grep 'Device:' | awk '{print $2}')"
# Colorized man pages: http://boredzo.org/blog/archives/2016-08-15/colorized-man-pages-understood-and-customized
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# Build a standalone Rust binary with no external dependencies
# Ex.: rust-musl-builder cargo build --release
# (via https://github.com/emk/rust-musl-builder)
alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder'
#########################################################################################
# Static named dirs
# (via https://twitter.com/tqbf/status/768513776664489984):
# hash -d .github=/Users/tqbf/codebase/go/src/github.com
# then this works: cd ~.github
hash -d projects=~/Projects
hash -d exercism=~/exercism
hash -d work=~/Work
#########################################################################################
# Editor aliases
alias e="${EDITOR}"
alias e.="${EDITOR} ."
alias m='mate'
alias m.='mate .'
alias v=e
alias v.='e.'
#########################################################################################
# Ruby aliases/functions
# Bundler:
alias be='bundle exec'
alias b='bundle'
# For Rails:
alias sc='./script/console'
alias sg='./script/generate'
alias ss='./script/server'
alias sd='./script/destroy'
alias pryr="pry -r ./config/environment -r rails/console/app -r rails/console/helpers"
function heftiest {
for file in $(find app/$1/**/*.rb -type f); do wc -l $file ; done | sort -r | head
}
function julia() {
/Applications/Julia-*.app/Contents/Resources/julia/bin/julia $*
}
function asmdoc() {
sqlite3 ~/.x86-64.sqlite "$(echo -e "SELECT description FROM instructions WHERE mnem=UPPER('$1')")" | $PAGER
}
##############################################################################
# Git aliases/functions/stuff
##############################################################################
alias g='git'
# mkdir .git/safe in the root of repositories you trust
export PATH=".git/safe/../../bin:$PATH"
##############################################################################
# Grep stuff
##############################################################################
# Grep in history
function greph () { history 0 | grep -i $1 }
# use colors when GNU grep with color-support
# Execute grep --color=auto
alias grep='grep --color=auto'
##############################################################################
# Xcode/iOS
##############################################################################
alias ded="rm -rf ${HOME}/Library/Developer/Xcode/DerivedData"
# Via http://www.mikeash.com/pyblog/solving-simulator-bootstrap-errors.html
alias unfuckbootstrap="launchctl list | grep UIKitApplication | awk '{print \$3}' | xargs launchctl remove"
# Nicked from http://cl.ly/1k0X0L2I033J0y0Y3V3a
function wtfxcode()
{
sudo spindump Xcode
local xcodefile=$(ls -t /tmp/Xcode* | tail -1)
sudo less $xcodefile
}
# Nicked from http://www.red-sweater.com/blog/2517/fixing-pngs
function fixpng ()
{
if [[ ! -f $1 ]] ; then
echo "Usage: fixpng <inputFiles> [outputFile]"
return -1
else
local inputFile=$1
local outputFile=$1
if [[ -e $2 ]] ; then
outputFile=$2
else
zmodload zsh/regex
local baseName=$1
[[ $inputFile -regex-match "^(.*).png" ]] && baseName=$match[1]
outputFile=$baseName-fixed.png
fi
echo Writing fixed PNG to $outputFile
xcrun -sdk iphoneos pngcrush -q -revert-iphone-optimizations $inputFile $outputFile
fi
}
# Fix a whole mess of pngs at once
function fixpngs ()
{
if [[ ! -f $1 ]] ; then
echo "Usage: fixpng <inputFiles> [outputFile]"
return -1
else
for i in "$@"; do fixpng ./"$i"; done;
fi
}
# Quickly purge the contents of all Simulators:
# (via https://twitter.com/bobmccune/status/692779281559199744)
alias purge-simulators='xcrun simctl erase all'
##############################################################################
# Functions for displaying neat stuff in *term title
##############################################################################
# format titles for screen and rxvt
function title() {
# escape '%' chars in $1, make nonprintables visible
a=${(V)1//\%/\%\%}
# Truncate command, and join lines.
a=$(print -Pn "%40>...>$a" | tr -d "\n")
case $TERM in
screen)
print -Pn "\e]2;$a @ $2\a" # plain xterm title
print -Pn "\ek$a\e\\" # screen title (in ^A")
print -Pn "\e_$2 \e\\" # screen location
;;
xterm*|rxvt)
print -Pn "\e]2;$a @ $2\a" # plain xterm title
;;
esac
}
# precmd is called just before the prompt is printed
function precmd () {
title "zsh" "%m(%55<...<%~)"
}
# preexec is called just before any command line is executed
function preexec () {
title "$1" "%m(%35<...<%~)"
}
##############################################################################
# Tell the terminal about the working directory whenever it changes.
##############################################################################
# Nabbed from http://apple.stackexchange.com/a/50334
if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL, including
# the host name to disambiguate local vs. remote paths.
# Percent-encode the pathname.
local URL_PATH=''
{
# Use LC_CTYPE=C to process text byte-by-byte.
local i ch hexch LC_CTYPE=C
for ((i = 1; i <= ${#PWD}; ++i)); do
ch="$PWD[i]"
if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then
URL_PATH+="$ch"
else
hexch=$(printf "%02X" "'$ch")
URL_PATH+="%$hexch"
fi
done
}
local PWD_URL="file://$HOST$URL_PATH"
#echo "$PWD_URL" # testing
printf '\e]7;%s\a' "$PWD_URL"
}
# Register the function so it is called whenever the working
# directory changes.
autoload add-zsh-hook
add-zsh-hook chpwd update_terminal_cwd
# Tell the terminal about the initial directory.
update_terminal_cwd
fi
##############################################################################
# rbenv/pyenv/swiftenv
##############################################################################
# rbenv
if type rbenv > /dev/null; then eval "$(rbenv init -)"; fi
# pyenv
if type pyenv > /dev/null; then eval "$(pyenv init -)"; fi
# swiftenv
if which swiftenv > /dev/null; then eval "$(swiftenv init -)"; fi
builtin rehash
##############################################################################
# Local Config
##############################################################################
# use .localrc for settings specific to one system
[[ -f "${HOME}/.zshrc.local" ]] && source "${HOME}/.zshrc.local"