-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.zshrc
More file actions
476 lines (409 loc) · 15.5 KB
/
.zshrc
File metadata and controls
476 lines (409 loc) · 15.5 KB
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
#####################################################################
# .zshrc by Niko Riitala <nri@iki.fi>. Twitter: @nikoriitala #
# Based on jdong's zshrc file #
# No copyright, feel free to use this, as you like. #
#####################################################################
# NOTE: this file is bloated and specific to my system
# you probably do not want to use this file bluntly
# possible points of interest:
# aliases, git-aware PS1, colors, functions, completion
# next lets set some enviromental/shell pref stuff up
# setopt NOHUP
#setopt NOTIFY
#setopt NO_FLOW_CONTROL
setopt INC_APPEND_HISTORY SHARE_HISTORY
setopt APPEND_HISTORY
# setopt AUTO_LIST # these two should be turned off
# setopt AUTO_REMOVE_SLASH
# setopt AUTO_RESUME # tries to resume command of same name
unsetopt BG_NICE # do NOT nice bg commands
setopt CORRECT # command CORRECTION
setopt EXTENDED_HISTORY # puts timestamps in the history
setopt HASH_CMDS # turns on hashing
setopt HASH_DIRS # turns on hashing
#
setopt MENUCOMPLETE
setopt ALL_EXPORT
bindkey "[3~" delete-char
# Set/unset shell options
setopt notify globdots correct pushdtohome cdablevars autolist
setopt correctall autocd recexact longlistjobs
setopt autoresume histignoredups pushdsilent
setopt autopushd extendedglob rcquotes mailwarning
unsetopt bgnice autoparamslash
# Autoload zsh modules when they are referenced
zmodload -a zsh/stat stat
zmodload -a zsh/zpty zpty
zmodload -a zsh/zprof zprof
#zmodload -ap zsh/mapfile mapfile
PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH:$HOME/scripts:$HOME/.local/bin:$HOME/.composer/vendor/bin"
TZ="Europe/Helsinki"
# History
export HISTFILE=$HOME/.zhistory
export HISTSIZE=10000
export SAVEHIST=10000
setopt hist_ignore_all_dups
#setopt hist_ignore_space
HOSTNAME="`hostname`"
PAGER='less'
EDITOR='vim'
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
(( count = $count + 1 ))
done
PR_NO_COLOR="%{$terminfo[sgr0]%}"
PS1="$PR_GREEN%n$PR_BLUE@$PR_YELLOW%m$PR_GREEN:$PR_BLUE%5c/$PR_NO_COLOR%(!.#.$) "
#LANGUAGE=
LC_ALL='fi_fi.UTF-8'
LANG='fi_FI.UTF-8'
LC_CTYPE=C
unsetopt ALL_EXPORT
# # --------------------------------------------------------------------
# # aliases
# # --------------------------------------------------------------------
# own aliases
# TODO - make separate file and/or categorize aliases
alias koko='identify -format "%wx%h"'
alias sr='screen -rd'
alias eject='drutil tray eject'
alias cupholder='eject' # legacy
alias scpresume='rsync --partial --progress'
alias un='tar -zxf'
alias ipscan='nmap -sP 192.168.1.1-255'
alias salakala='pwgen -Bs 10 1'
alias salakala_serious_business='pwgen -ys 30 1'
alias tetris='emacs -q --no-splash -f tetris'
alias links2='links2 -g'
alias slrn='slrn -n'
alias man='LC_ALL=C LANG=C man'
alias f=finger
alias offlineimap-tty='offlineimap -u TTY.TTYUI'
alias hnb-partecs='hnb $HOME/partecs/partecs-hnb.xml'
alias rest2html-css='rst2html --embed-stylesheet --stylesheet-path=/usr/share/python-docutils/s5_html/themes/default/print.css'
alias cp='cp -i'
alias du='du -h'
alias ducks='du -cks * | sort -rn | head'
alias df='df -h'
alias xc='exit'
alias errorlog='watch -n5 "tail -65 /var/log/apache2/error.log"'
alias icanhas='sudo apt-get install'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get upgrade'
alias remove='sudo apt-get remove'
alias search='apt-cache search'
alias mysli='mysql -u root -p"PASSHERE"'
alias apt='sudo apt-get'
alias vi='vim'
alias greps='grep -A5 -B5'
alias tmux='tmux -2'
alias vimrc='vi ~/.vimrc'
alias zshrc='vi ~/.zshrc'
alias hosts='vi /etc/hosts'
alias vhosts='sudo vi /etc/apache2/sites-enabled/vhosts'
alias calc='qalc'
alias devscp='rsync -av --rsh "ssh dev ssh"'
alias irs='ssh -t xob screen -rd'
alias tyokalenteri='gcalcli calm --monday --width 15 --military'
alias wadap='gcalcli agenda'
alias palaverit='google calendar list --date today,tomorrow'
alias spotify='$HOME/scripts/spotify-control.sh'
alias myip='echo "Public ip address:" && curl http://wtfismyip.com/text'
alias cal='ncal -MC'
# directory management
alias ls='ls --color=auto'
alias l='ll'
alias lsu='ls -lAhtr'
alias la='ll -a'
alias lsd='ls -l | grep "^d"'
alias d='dirs -v | head -9 | tail -8'
alias 1='cd +1'
alias 2='cd +2'
alias 2='cd +2'
alias 3='cd +3'
alias 4='cd +4'
alias 5='cd +5'
alias 6='cd +6'
alias 7='cd +7'
alias 8='cd +8'
alias 9='cd +9'
alias tyo_umount='fusermount -u $HOME/Roinaa/tyoasiat && rmdir $HOME/Roinaa/tyoasiat'
alias tyo_mount='mkdir $HOME/Roinaa/tyoasiat && encfs $HOME/Roinaa/.encrypted $HOME/Roinaa/tyoasiat || rmdir $HOME/Roinaa/tyoasiat'
# typing errors
alias sl='ls'
alias sco='scp'
alias spc='scp'
alias ci='vi'
alias exiy='exit'
alias exity='exit'
alias dc='cd'
alias cd.='cd ..'
alias ...='git-root'
alias gerp='grep'
alias iv='vi'
# git
alias g='git'
alias gi='git init'
alias gs='git status'
alias ga='git add'
alias gp='git push'
alias gl='git pull'
alias gd='git diff'
alias gc='git commit -v'
alias gcl='git clone'
alias gca='git commit -v -a'
alias git-root='cd $(git rev-parse --show-cdup)'
alias gll="git log --graph --date=short --pretty=format:'%Cred%h%Creset -%C(yellow)%Creset %s %Cgreen(%cd, %C(yellow)%cr%Cgreen) %C(bold blue)<%an>%Creset' --abbrev-commit"
# check out what have i done today
alias glll="git log --graph --pretty=format:'%h (%ad) %an: %s' --date=short | grep `date +%Y-%m-%d` | cut -d ':' -f 3- | paste -s -d ','"
alias gf='git diff --name-only HEAD~1 master'
alias gcw='git commit -a -m "$(whatthecommit)"'
alias gfiles='git diff-tree --no-commit-id --name-only -r'
alias glog='git shortlog'
alias glogi='git shortlog -s -n --no-merges'
alias master='git checkout master'
alias git-remote-activity='for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r'
# drush
alias dst='drush status -show-password'
alias ddl='drush dl'
function ddlen() { drush dl "$@" && drush en "$@" -y ; }
alias ddls='drush dl --select'
alias den='drush en -y'
alias ddis='drush dis -y'
alias dup='drush up -y'
alias dcca='drush cc all'
alias dcron='drush cron'
alias dpml='drush pml'
alias duli='drush uli | sed -e "s/^.*user/user/g"'
alias drdb='drush sql-dump --ordered-dump --result-file=dump.sql'
alias drun='drush pm-uninstall'
alias drfe='drush features'
alias dr='drush'
alias dr7='drush7'
alias drush7='/home/niko/.composer/vendor/bin/drush'
alias ddiscache='drush vset cache 0 && drush vset page_compression 0 && drush vset preprocess_js 0 && drush vset preprocess_css 0'
alias dencache='drush vset cache 1 && drush vset page_compression 1 && drush vset preprocess_js 1 && drush vset preprocess_css 1'
alias dsdump='drush sql-dump --result-file=dump.sql'
alias doffline='drush vset maintenance_mode 1 --yes'
alias donline='drush vset maintenance_mode 0 --yes'
function dupwd() { PW=`pwgen -Bs 10 1`; drush upwd --password="${PW}" admin && echo "New password for admin: ${PW}" }
autoload -U compinit
compinit
# keybinds
bindkey '[1~' beginning-of-line
bindkey '[4~' end-of-line
bindkey '[H' beginning-of-line
bindkey '[F' end-of-line
bindkey '^[[5~' up-line-or-history
bindkey '^[[6~' down-line-or-history
bindkey "^r" history-incremental-search-backward
bindkey ' ' magic-space # also do history expansion on space
bindkey '^I' complete-word # complete on tab, leave expansion to _expand
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' menu select=1 _complete _ignored _approximate
zstyle -e ':completion:*:approximate:*' max-errors \
'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
# Completion Styles
# list of completers to use
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
# allow one error for every three characters typed in approximate completer
zstyle -e ':completion:*:approximate:*' max-errors \
'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'
# insert all expansions for expand completer
zstyle ':completion:*:expand:*' tag-order all-expansions
# formatting and messages
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''
# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# offer indexes before parameters in subscripts
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# command for process lists, the local web server details and host completion
# on processes completion complete all user processes
zstyle ':completion:*:processes' command 'ps -au$USER'
## add colors to processes for kill completion
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
#NEW completion:
# 1. All /etc/hosts hostnames are in autocomplete
# 2. If you have a comment in /etc/hosts like #%foobar.domain,
# then foobar.domain will show up in autocomplete!
zstyle ':completion:*' hosts $(awk '/^[^#]/ {print $2 $3" "$4" "$5}' /etc/hosts | grep -v \.local | grep -v ip6- && grep "^#%" /etc/hosts | awk -F% '{print $2}')
# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
'*?.old' '*?.pro'
# ignore completion functions (until the _ignored completer)
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:*:*:users' ignored-patterns \
adm apache bin daemon games gdm halt ident junkbust lp mail mailnull \
named news nfsnobody nobody nscd ntp operator pcap postgres radvd \
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs avahi-autoipd\
avahi backup messagebus beagleindex debian-tor dhcp dnsmasq fetchmail\
firebird gnats haldaemon hplip irc klog list man cupsys postfix\
proxy syslog www-data mldonkey sys snort
# SSH Completion
zstyle ':completion:*:scp:*' tag-order \
files users 'hosts:-host hosts:-domain:domain hosts:-ipaddr"IP\ Address *'
zstyle ':completion:*:scp:*' group-order \
files all-files users hosts-domain hosts-host hosts-ipaddr
zstyle ':completion:*:ssh:*' group-order \
hosts-domain hosts-host users hosts-ipaddr
zstyle '*' single-ignored show
if [[ ${TERM} == "screen-bce" || ${TERM} == "screen" ]]; then
precmd () { print -Pn "\033k\033\134\033k%1d/\033\134" }
preexec () {
local CMD=${1[(wr)^(<*|*=*|sudo|exec|-*)]}
echo -n "\ek$CMD\e\\"
}
else
precmd () { print -Pn "\e]0;%n@%m: %~\a" }
preexec () { print -Pn "\e]0;%n@%m: $1\a" }
fi
eval $(dircolors ~/.dir_colors)
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
setopt promptsubst
setopt prompt_subst
autoload colors
colors
autoload -Uz vcs_info
# set some colors
for COLOR in RED GREEN YELLOW WHITE BLACK CYAN; do
eval PR_$COLOR='%{$fg[${(L)COLOR}]%}'
eval PR_BRIGHT_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
done
PR_RESET="%{${reset_color}%}";
FMT_BRANCH="${PR_GREEN}%b%u%c${PR_RESET}" # e.g. master¹²
FMT_ACTION="(${PR_CYAN}%a${PR_RESET}%)" # e.g. (rebase-i)
FMT_PATH="%R${PR_YELLOW}/%S" # e.g. ~/repo/subdir
# check-for-changes can be really slow.
# you should disable it, if you work with large repositories
zstyle ':vcs_info:*:prompt:*' check-for-changes true
zstyle ':vcs_info:*:prompt:*' unstagedstr '¹' # display ¹ if there are unstaged changes
zstyle ':vcs_info:*:prompt:*' stagedstr '²' # display ² if there are staged changes
zstyle ':vcs_info:*:prompt:*' actionformats "${FMT_BRANCH}${FMT_ACTION}//" "${FMT_PATH}"
zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}" "${FMT_PATH}"
zstyle ':vcs_info:*:prompt:*' nvcsformats "" "%~"
function precmd {
vcs_info 'prompt'
}
function prompti {
local brackets=$1
local color1=$2
local color2=$3
local at="${color1}@${PR_RESET}"
local bracket_open="${color1}${brackets[1]}${PR_RESET}"
local bracket_close="${color1}${brackets[2]}${PR_RESET}"
local git='$vcs_info_msg_0_'
local cwd="${color2}%B%1~%b"
PROMPT="$PR_GREEN%n$PR_BLUE@$PR_YELLOW%m$PR_GREEN:$PR_BLUE%5c/$PR_NO_COLOR${bracket_open}${git}${bracket_close} %(!.#.$) "
}
function www {
if [ -z $1 ]; then
cd /var/www
else
cd $(echo `find /var/www -maxdepth 3 -type d -name $1 -print0 -quit`)
fi
}
prompti '[]' $BR_BRIGHT_BLACK $PR_WHITE
zle-keymap-select() {
if [[ $KEYMAP = vicmd ]]; then
echo -ne "\033]12;Red\007"
else
echo -ne "\033]12;Green\007"
fi
}
zle -N zle-keymap-select
zle-line-init () {
zle -K viins
if [ $TERM = "rxvt-256color" ]; then
echo -ne "\033]12;Green\007"
fi
}
zle -N zle-line-init
bindkey -v
bindkey -M viins '^R' history-incremental-pattern-search-backward
bindkey -M viins '^F' history-incremental-pattern-search-forward
# exports
export GREP_COLOR='1;33'
export CLICOLOR=1
export DIRSTACKSIZE=9
export code="$HOME/code/"
export temp="$HOME/temp/"
export roinaa="$HOME/Roinaa/"
export work="$HOME/Work/"
export TERM=xterm-256color
source ~/.zsh/.git-completion.sh
source ~/.zsh/.git-flow-completion.sh
export LC_ALL=en_US.UTF-8
bindkey "[3~" delete-char
umask 002
# export display when logging from remote
# [ -n "$SSH_CLIENT" ] && export DISPLAY=$(echo $SSH_CLIENT | awk '{ print $1 }'):0.0
[ -n "$SSH_CLIENT" ] && export DISPLAY=:0.0
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[ -s "$HOME/.scm_breeze/scm_breeze.sh" ] && source "$HOME/.scm_breeze/scm_breeze.sh"
[ -s "$HOME/scripts/grep_with_file_shortcuts.zsh" ] && source "$HOME/scripts/grep_with_file_shortcuts.zsh"
alias gl='git pull'
# {{{ Functions
diffcolor(){ diff -U3 $1 $2 |sed -e 's/^+/\x1b\[32m+/;s/^-/\x1b[31m-/;s/$/\x1b[0m/'; }
# convert png to ico file, needs imagemagick
function png2ico() { convert $1 -resize 16x16 -colors 256 $2 ;}
# create directory and access it
mcd(){mkdir -p "$1" && cd "$1"}
# run $2 $1 times
function manytimes {
n=0
times=$1
shift
while [[ $n -lt $times ]]; do
$@
n=$((n+1))
done
}
function xrdbload() {
xrdb -load ~/.Xdefaults && xrdb -load ~/.Xresources
}
function whatthecommit() {
curl -s http://whatthecommit.com | perl -p0e '($_)=m{<p>(.+?)</p>}s'
}
# }}}
# {{{ Antigen external plugins
#source $HOME/antigen/antigen.zsh
# Custom bundles
#antigen bundle robbyrussell/oh-my-zsh plugins/jira
#antigen-bundle zsh-users/zsh-history-substring-search
#bindkey "$terminfo[kcuu1]" history-substring-search-up
#bindkey "$terminfo[kcud1]" history-substring-search-down
# Bundles from the default repo (robbyrussell's oh-my-zsh).
#antigen bundle git
#antigen bundle heroku
#antigen bundle pip
#antigen bundle lein
#antigen bundle command-not-found
# Tell antigen that you're done.
#antigen apply
# }}}
setxkbmap -option caps:none
# fix ruby rvm
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
if [ -r /home/linuxbrew/.linuxbrew/Cellar/mcfly/v0.5.0/mcfly.zsh ]; then
. /home/linuxbrew/.linuxbrew/Cellar/mcfly/v0.5.0/mcfly.zsh
fi
# Install Ruby Gems to ~/gems
export GEM_HOME="$HOME/gems"
export PATH="$HOME/gems/bin:$PATH"
[ -s "/home/niko/.scm_breeze/scm_breeze.sh" ] && source "/home/niko/.scm_breeze/scm_breeze.sh"