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