summaryrefslogtreecommitdiff
path: root/.zsh/zshrc
blob: 8768b52c9071c6c10764157188a8132d490e086c (plain)
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
# provide the is-at-least command
autoload is-at-least

# check for Gentoo
if [[ -e /etc/gentoo-release ]]; then
    _IS_GENTOO=1
fi

# Alias definition {{{
#################################################

# directory aliases
[[ -n $_IS_GENTOO ]] && hash -d ulp=/usr/local/portage

# the | cmd aliases
alias -g L='| less'
alias -g H='| head'
alias -g T='| tail'
alias -g G='| grep'

# > aliases
alias -g NE='2> /dev/null'
alias -g NO='> /dev/null'
alias -g NOE='&> /dev/null'

# "vim" mappings
alias :e='gvim'
alias :q='exit'

# ls
alias ls='ls --color=auto'
alias ll='ls -l'
alias la='ls -a'

# prevent man from using localized pages
alias man='LANG= man'

if [[ -n $_IS_GENTOO ]]; then
    # emerge stuff
    alias AK="ACCEPT_KEYWORDS=\"$_kw\"" # _kw should be set in .zshenv
    alias NS='FEATURES="nostrip" CFLAGS="-O0 -ggdb -pipe -march=native" CXXFLAGS="${CFLAGS}"'
    alias e="eix -e"
    alias i="eix -I"
    alias ee='open_ebuild vim'
    alias eeg='open_ebuild gvim'
    alias cdu='open_ebuild _cdu'
    alias unpack='open_ebuild _unpack'
fi

# misc
alias quickweb='python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"'
alias CH='./configure --help | less'
alias FF='noglob firefox'
alias bt="bsdtar"

# suffixes
[[ -n $_IS_WINDOWS ]] || alias -s exe='wine'
alias -s pdf='xdg-open'
alias -s JPG='feh -F'
alias -s jpg='feh -F'
alias -s png='feh -F'
alias -s zip='unzip'
alias -s gz='tar -xf'
alias -s bz2='tar -xf'
alias -s rar='rar -e'
alias -s mp3='mplayer'
alias -s ogg='mplayer'
alias -s flac='mplayer'
alias -s odt='soffice'
alias -s ods='soffice'

# the config management stuff
alias config='git --git-dir=$HOME/.config.git/ --work-tree=$HOME'
alias cstg='GIT_DIR=$HOME/.config.git stg'
alias caf='config add -f'

# }}}

# Functions {{{
#################################################

source ~/.zsh/zshfunctions

# }}}

# Make sure term capabilities are existing {{{
if whence infocmp tic NOE && ! infocmp NOE; then
    fix_terminfo
    TERM=$TERM # this forces a reinit
fi
# }}}

# Test for an interactive shell {{{ 
# There is no need to set anything past this point for scp and rcp, 
# and it's important to refrain from outputting anything in those cases.
if [[ $- != *i* ]] ; then
 # Shell is non-interactive.  Be done now!
    return
fi
# }}}

# General ZSH Functionality {{{
#################################################

autoload -Uz add-zsh-hook

# }}}

# Completion {{{
#################################################
autoload -U compinit 
compinit

zmodload -i zsh/complist
zstyle ':completion::complete:*' use-cache 1

# the different style options
zstyle ":completion:*" verbose yes # be verbose
zstyle ":completion:*:descriptions" format "%S%d%s" # show descriptions
zstyle ":completion:*:corrections" format "%S%d%s"
zstyle ":completion:*:warnings" format "%S%d%s"
zstyle ":completion:*:errors" format "%S%d%s"

zstyle ":completion:*" menu select=2 # show menu
zstyle ":completion:*:default" select-prompt "%SMatch %M    %P%s" # show statusline

zstyle ":completion::complete:*" rehash true # rehash always :)

# colors
[[ -z $LS_COLORS ]] && eval $(dircolors) # needed for next line
zstyle ":completion:*:default" list-colors ${(s.:.)LS_COLORS} # make filecompletions being colored

# do not show the current directory for e.g. cd ../<TAB>
zstyle ':completion:*:cd:*' ignore-parents parent pwd

# }}}

# Prompt {{{
#################################################
add-zsh-hook -Uz precmd promptnl # always guarantee a newline

autoload -U promptinit
promptinit

local prompt_color="green red"
[[ -n "$SSH_CLIENT" ]] && prompt_color="yellow cyan"

prompt necoro  blue ${=prompt_color}

# remove RPROMPT when command finished
setopt transient_rprompt

# load colors
autoload -U colors
colors

# show smilies in prompt :)
RPROMPT="%(?.%S%{$fg[green]%}:).%S%{$fg[red]%}:()%{$reset_color%}%s"

# Screen indication
[[ $TERM == "screen*" ]] && RPROMPT="${RPROMPT} %B%{$fg[cyan]%}(S #$WINDOW)%{$reset_color%}%b"

# vcs stuff for prompt
setopt prompt_subst

if is-at-least 4.3.9; then
    autoload -Uz vcs_info

    zstyle ":vcs_info:*" enable cvs svn git hg
    zstyle ":vcs_info:*" formats "%B%{$fg[yellow]%}[%{$fg[green]%}(%u%c) %{$fg[yellow]%}%b:%1.7i%f%%b (%s)%B%{$fg[yellow]%}]%f%%b"
    zstyle ":vcs_info:*" branchformat "%b"
    zstyle ":vcs_info:*" get-revision true
    zstyle ":vcs_info:*" check-for-changes true
    zstyle ":vcs_info:*" max-exports 1

    # hg stuff
    zstyle ":vcs_info:hg:*" unstagedstr '*'
    zstyle ":vcs_info:hg:*" hgrevformat '%r'

    RPROMPT='${vcs_info_msg_0_:+"${vcs_info_msg_0_} "}'"${RPROMPT}"

    add-zsh-hook precmd vcs_info
fi


# }}}

# XTerm Window Title {{{
#################################################
_set_title () {
    local pre post

    case $TERM in
        xterm*|*rxvt*)
            pre="\033]0;"
            post="\007";;
        screen*)
            pre="\033k"
            post="\033\\";;
        linux)
            return;;
    esac
    echo  -ne "${pre}${USER}@${HOST}:${PWD/$HOME/~}${post}"
}
add-zsh-hook precmd _set_title

_set_cwd () {
    local update="\0033]777;cwd-spawn;path;$PWD\0007"

    case $TERM in
        screen*)
        # pass through to parent terminal emulator
            update="\0033P$update\0033\\";;
        linux) return;;
    esac

    echo -ne "$update"
}
add-zsh-hook chpwd _set_cwd

case $TERM in
xterm*)
    # force xterm 256
    TERM=xterm-256color
    ;;
esac

# exec once for initialization
_set_cwd
# }}}

# Key bindings {{{
#################################################
bindkey -e # use emacs style :)

if is-at-least 4.3.9; then
    bindkey "^R" history-incremental-pattern-search-backward
    bindkey "^S" history-incremental-pattern-search-forward
else
    bindkey "^R" history-incremental-search-backward
    bindkey "^S" history-incremental-search-forward
fi

bindkey "^[-" copy-prev-word

# delete previous word upto next whitespace
bindkey "^ew" backward-kill-word

# some 'insert x before' things
for word c in sudo s vim v AK a; do
    eval "insert-$word() { LBUFFER=\"$word \$LBUFFER\" }"
    zle -N insert-$word
    bindkey "^[i$c" insert-$word
done

# use only local history on arrow-up
# but also imported one when using C-r
zle-line-init()  { NUMERIC=1 zle set-local-history }
zle -N zle-line-init

zle-isearch-update() { NUMERIC=0 zle set-local-history }
zle -N zle-isearch-update

zle-isearch-exit()  { NUMERIC=1 zle set-local-history }
zle -N zle-isearch-exit

# fix Del, Pos1, End
case $TERM in 
    xterm*)
        bindkey "^[OH" beginning-of-line
        bindkey "^[OF" end-of-line
        bindkey "^[[3~" delete-char
        ;;
    *rxvt*)
        bindkey "^[[7~" beginning-of-line
        bindkey "^[[8~" end-of-line
        bindkey "^[[3~" delete-char
        ;;
    screen*|linux)
        bindkey "^[[1~" beginning-of-line
        bindkey "^[[4~" end-of-line
        bindkey "^[[3~" delete-char
        ;;
esac
# }}}

# History {{{
#################################################
HISTSIZE=10000
SAVEHIST=12000
HISTFILE=~/.zshhistory
setopt hist_no_store # do not store history related commands
setopt inc_append_history # append incrementally instead of waiting until the shell exists
setopt share_history # share the history between sessions
setopt hist_verify # for history related commands: reload the expanded version instead of executing it directly
setopt hist_no_functions # do not store function definitions
setopt hist_ignore_space # do not store lines starting with ' '

setopt hist_ignore_dups # ignore duplicates
setopt hist_ignore_all_dups # ignore _all_ duplicates

# }}}

# Misc Options {{{
#################################################
setopt no_notify # do not disturb if bg-process has quit
setopt no_bg_nice # start bg-processes with the same nice-level as fg-p~
setopt auto_cd # if you type a dir take it as a cd
setopt correct # correct possibly wrong command names
setopt complete_in_word
setopt auto_continue # disown implies 'bg'

# }}}

# Rest {{{
#################################################

# load zmv
autoload -Uz zmv

# cdr
autoload -Uz chpwd_recent_dirs cdr
add-zsh-hook chpwd chpwd_recent_dirs

zstyle ':completion:*:*:cdr:*:*' menu selection
zstyle ':chpwd:*' recent-dirs-default true
zstyle ':completion:*' recent-dirs-insert both

# }}}

# Cleanup {{{
#################################################

unset _IS_GENTOO

# }}}
# vim: fdm=marker