]> Sergey Matveev's repositories - dotfiles.git/blob - zsh/.zshrc
zsh URL quoting
[dotfiles.git] / zsh / .zshrc
1 # vim: foldmethod=marker:foldlevel=0
2
3 # Basic options {{{
4 setopt INTERACTIVE_COMMENTS
5 setopt GLOB_STAR_SHORT GLOB_DOTS EXTENDED_GLOB
6 setopt NO_NOMATCH
7 setopt AUTO_PUSHD PUSHD_IGNORE_DUPS
8
9 setopt RM_STAR_SILENT
10 export LISTMAX=9999
11 # }}}
12
13 # History options {{{
14 setopt APPEND_HISTORY SHARE_HISTORY INC_APPEND_HISTORY HIST_IGNORE_ALL_DUPS
15 setopt HIST_IGNORE_SPACE
16 HISTORY_IGNORE="(yt* *|t *|t|mmfileget *|arr|rss)"
17 # }}}
18
19 # Vi mode {{{
20 bindkey -v
21 export KEYTIMEOUT=1
22 # }}}
23
24 # Home/end {{{
25 bindkey "^[[1~" beginning-of-line
26 bindkey "^[[4~" end-of-line
27 # }}}
28
29 # Command-line editing {{{
30 autoload -U edit-command-line
31 zle -N edit-command-line
32 bindkey -M vicmd v edit-command-line
33 # }}}
34
35 # History search {{{
36 autoload -U history-search-end
37 zle -N history-beginning-search-backward-end history-search-end
38 zle -N history-beginning-search-forward-end history-search-end
39 bindkey "^[[A" history-beginning-search-backward-end
40 bindkey "^[[B" history-beginning-search-forward-end
41
42 beginning-history-incremental-pattern-search-backward() {
43     zle history-incremental-pattern-search-backward $(echo $BUFFER | sed "s/ /*/g")
44 }
45 zle -N beginning-history-incremental-pattern-search-backward
46 bindkey "^[[1;2A" beginning-history-incremental-pattern-search-backward
47 bindkey -M isearch "^[[A" history-incremental-pattern-search-backward
48 bindkey -M isearch "^[[B" history-incremental-pattern-search-forward
49 # }}}
50
51 # URL quoting {{{
52 autoload -U url-quote-magic
53 autoload -U bracketed-paste-magic
54 zle -N self-insert url-quote-magic
55 zle -N bracketed-paste bracketed-paste-magic
56 # }}}
57
58 # Prompt {{{
59 function zle-line-init zle-keymap-select {
60     mode_vi="${${KEYMAP/vicmd/+}/(main|viins)/-}"
61     [ $timer ] && timer_show=$(( $SECONDS - $timer ))
62     prompt="%2~|"
63     prompt+="%U${timer_show}%u|"
64     prompt+="%B%?%b"
65     prompt+="${mode_vi}"
66     prompt+="%B%F{magenta}%#%f%b "
67     PS1="$prompt"
68     zle reset-prompt
69 }
70 zle -N zle-line-init
71 zle -N zle-keymap-select
72
73 preexec() {
74     timer=$SECONDS
75 }
76
77 precmd() {
78     printf "\a\033]2;\033\\"
79 }
80 # }}}
81
82 # Aliases {{{
83 alias l="ls -AF "
84 alias ll="ls -AFl "
85 alias ssh="TERM=xterm ssh"
86 alias vi="vim"
87 alias more="less"
88 alias m="less "
89 alias -g M="| less"
90 alias -g W="| wc -l"
91 alias mc="mc --nomouse"
92 bindkey -s "\eOS" " popd\n" # F4
93
94 f() {
95     # find . -name "*$1*" -print
96     print -C 1 **$1*
97 }
98
99 ssht() {
100     ssh -C -t "$1" tmux attach -t0
101 }
102 alias sshnm="ssh -S none"
103 # }}}
104
105 # Git {{{
106 alias Ga="git add"
107 alias Gb="git branch"
108 alias Gc="git checkout"
109 alias Gd="git diff"
110 alias Gs="git show"
111 alias Gm="git diff --name-only --diff-filter=M"
112 alias Gam="git commit --amend"
113
114 git_common="--oneline --abbrev-commit"
115 alias Gl="git log $git_common --graph --decorate=short"
116 alias Gr="git --no-pager log $git_common -n 20 | perl -ne 'print \"@~\$n \$_\"; \$n++'"
117 alias Grr="git --no-pager log $git_common --graph -n 1024 | vi -c 'setlocal filetype=gitrebase buftype=nofile noswapfile' -"
118
119 bindkey -s "\eOQ" " git status\n" # F2
120 bindkey -s "\eOR" " git status --short\n" # F3
121 # }}}
122
123 # grep {{{
124 GREP=/usr/local/bin/grep
125 GREP_ARGS="--color=always --with-filename --line-number --recursive"
126 LESS_COLORED="less --RAW-CONTROL-CHARS"
127 g() {
128     $GREP ${=GREP_ARGS} $@ | ${=LESS_COLORED}
129 }
130 GS() {
131     $GREP ${=GREP_ARGS} $@ | sort --numeric-sort | ${=LESS_COLORED}
132 }
133 alias -g G="| $GREP --color"
134 alias gg="git grep "
135 # }}}
136
137 # GPG agent {{{
138 GPG_TTY=$(tty)
139 export GPG_TTY
140 # }}}
141
142 # Virtualenv {{{
143 venv() {
144     . /usr/local/bin/virtualenvwrapper.sh
145 }
146 # }}}
147
148 # Mail {{{
149 mailpath=(
150     ~/mail/mbox"?Neue Nachrichten in =mbox"
151     ~/mail/arbeit"?Neue Nachrichten in =arbeit"
152 )
153 alias arr="mutt -f \=arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
154 alias rss="mutt -f \=rss"
155 bindkey -s "\eOP" " inc\n" # F1
156 # }}}
157
158 # Calculator {{{
159 autoload -U zcalc
160 alias zc="zcalc"
161 # }}}
162
163 # Named directories {{{
164 . ~/.zhashd
165 # }}}
166
167 # Completion {{{
168 zstyle ":completion:*:functions" ignored-patterns "_*"
169 zstyle ":completion:*" matcher-list "" 'm:{a-z\-}={A-Z\_}' 'r:|?=** m:{a-z\-}={A-Z\_}'
170 _mycomp () {
171     [ "$words[1]" != "man" ] || { _man && return 0 }
172     [ $CURRENT -eq 1 ] && _command_names ||  _files && return 0
173     # MAGIC_EQUAL_SUBST {{{
174     [[ "$PREFIX" = *\=* ]] || return 1
175     compstate[parameter]="${PREFIX%%\=*}"
176     compset -P 1 "*="
177     _value
178     # }}}
179 }
180 zstyle ":completion:*" completer _mycomp _parameters
181 autoload -U compinit ; compinit -d /tmp/.zcompdump
182 zstyle ":completion:*:default" list-colors ""
183 autoload -U complist
184 # }}}
185
186 # Highlighting {{{
187 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
188 . ~/work/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
189 typeset -A ZSH_HIGHLIGHT_STYLES
190 ZSH_HIGHLIGHT_STYLES[assign]="fg=cyan"
191 ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
192 ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fg=green,bold"
193 ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fg=green"
194 ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
195 ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
196 ZSH_HIGHLIGHT_STYLES[redirection]="fg=red"
197 ZSH_HIGHLIGHT_STYLES[path]="fg=white,underline"
198 ZSH_HIGHLIGHT_STYLES[path_pathseparator]="fg=white,bold,underline"
199 # }}}
200
201 # Autosuggestion {{{
202 . ~/work/zsh-autosuggestions/zsh-autosuggestions.zsh
203 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
204 # }}}