]> Sergey Matveev's repositories - dotfiles.git/blobdiff - zsh/.zshrc
Huge tmux-fzf simplification with files quoting
[dotfiles.git] / zsh / .zshrc
index afd966782203ba34275bc0e8ea3d8db21af48fc6..b0c5e6a3c39af07fcc79d5a69a127cc33739248c 100644 (file)
@@ -1,12 +1,20 @@
 # vim: foldmethod=marker:foldlevel=0
 
 # Basic options {{{
-setopt APPEND_HISTORY SHARE_HISTORY INC_APPEND_HISTORY HIST_IGNORE_ALL_DUPS
-setopt HIST_IGNORE_SPACE
 setopt INTERACTIVE_COMMENTS
 setopt GLOB_STAR_SHORT GLOB_DOTS EXTENDED_GLOB
 setopt NO_NOMATCH
 setopt AUTO_PUSHD PUSHD_IGNORE_DUPS
+setopt PIPE_FAIL
+
+setopt RM_STAR_SILENT
+export LISTMAX=9999
+# }}}
+
+# History options {{{
+setopt APPEND_HISTORY SHARE_HISTORY INC_APPEND_HISTORY HIST_IGNORE_ALL_DUPS
+setopt HIST_IGNORE_SPACE
+HISTORY_IGNORE="(yt* *|t *|t|sdcv *|mmfileget *|arr)"
 # }}}
 
 # Vi mode {{{
@@ -31,19 +39,26 @@ zle -N history-beginning-search-backward-end history-search-end
 zle -N history-beginning-search-forward-end history-search-end
 bindkey "^[[A" history-beginning-search-backward-end
 bindkey "^[[B" history-beginning-search-forward-end
-bindkey "^R" history-incremental-search-backward
+
+beginning-history-incremental-pattern-search-backward() {
+    zle history-incremental-pattern-search-backward ${BUFFER:gs/ /*/}
+}
+zle -N beginning-history-incremental-pattern-search-backward
+bindkey "^[[1;2A" beginning-history-incremental-pattern-search-backward
+bindkey -M isearch "^[[A" history-incremental-pattern-search-backward
+bindkey -M isearch "^[[B" history-incremental-pattern-search-forward
 # }}}
 
 # Prompt {{{
 function zle-line-init zle-keymap-select {
-    mode_vi="${${KEYMAP/vicmd/+}/(main|viins)/-}"
-    [ $timer ] && timer_show=$(( $SECONDS - $timer ))
+    mode_vi=${${KEYMAP/vicmd/+}/(main|viins)/-}
+    [[ $timer ]] && timer_show=$(( $SECONDS - $timer ))
     prompt="%2~|"
     prompt+="%U${timer_show}%u|"
     prompt+="%B%?%b"
     prompt+="${mode_vi}"
-    prompt+="%F{magenta}%#%f "
-    PS1="$prompt"
+    prompt+="%B%F{magenta}%#%f%b "
+    PS1=$prompt
     zle reset-prompt
 }
 zle -N zle-line-init
@@ -54,16 +69,8 @@ preexec() {
 }
 
 precmd() {
-    print -n "\a"
-}
-# }}}
-
-# Tmux pane name {{{
-CTP()
-{
-    printf "\033]2;\033\\"
+    printf "\a\033]2;\033\\"
 }
-CTP
 # }}}
 
 # Aliases {{{
@@ -74,8 +81,10 @@ alias vi="vim"
 alias more="less"
 alias m="less "
 alias -g M="| less"
-alias mc="mc ; CTP"
-bindkey -s "\eOS" " popd\n" # F4
+alias -g W="| wc -l"
+alias mc="mc --nomouse"
+alias sent="mutt -f =sent-\`date '+%y-%m'\`"
+alias zc=~/bin/dc-wrapped.sh
 
 f() {
     # find . -name "*$1*" -print
@@ -83,19 +92,26 @@ f() {
 }
 
 ssht() {
-    ssh -C -t "$1" tmux attach -t0
+    ssh -C -t $1 tmux attach -t0
 }
-alias sshnm='ssh -o "ControlMaster no"'
+alias sshnm="ssh -S none"
 # }}}
 
-# Lynx {{{
-lwe() {
-    lynx -cookies "https://en.wikipedia.org/wiki/$1"
+# Faster movement {{{
+cddotdot() {
+    cd ..
+    pwd
+    zle reset-prompt
 }
+zle -N cddotdot
+bindkey "\eOQ" cddotdot # F2
 
-lwr() {
-    lynx -cookies "https://ru.wikipedia.org/wiki/$1"
+pushdquiet() {
+    popd
+    zle reset-prompt
 }
+zle -N pushdquiet
+bindkey "\eOS" pushdquiet # F4
 # }}}
 
 # Git {{{
@@ -103,27 +119,30 @@ alias Ga="git add"
 alias Gb="git branch"
 alias Gc="git checkout"
 alias Gd="git diff"
-alias Gs="git show"
+alias Gdc="git diff --cached"
+alias Gs="git show --show-signature"
 alias Gm="git diff --name-only --diff-filter=M"
 alias Gam="git commit --amend"
 
-git_common="--oneline --abbrev-commit"
-alias Gl="git log $git_common --graph --decorate=short"
-alias Gr="git --no-pager log $git_common -n 20 | perl -ne 'print \"@~\$n \$_\"; \$n++'"
-alias Grr="git --no-pager log $git_common --graph -n 1024 | vi -c 'e ++enc=utf8' -"
-alias Grpck="git gc --prune=now ; git repack -a -d --depth=4095 --window=10240"
+alias Gl="git log --oneline --graph --decorate=short"
+alias Gld="git log --format=format:'%ai %Cgreen%h%Creset %s'"
+alias Gr="git --no-pager log --oneline -n 20 | perl -ne 'print \"@~\$n \$_\"; \$n++'"
+alias Grr="git --no-pager log --oneline --graph -n 1024 | vi -c 'setlocal filetype=gitrebase buftype=nofile noswapfile' -"
 
-bindkey -s "\eOQ" " git status\n" # F2
 bindkey -s "\eOR" " git status --short\n" # F3
 # }}}
 
 # grep {{{
 GREP=/usr/local/bin/grep
+GREP_ARGS="--color=always --with-filename --line-number --dereference-recursive"
+LESS_COLORED="less --RAW-CONTROL-CHARS"
 g() {
-    $GREP --color=always --with-filename --line-number --recursive $@ | less --RAW-CONTROL-CHARS
+    $GREP ${=GREP_ARGS} $@ | ${=LESS_COLORED}
+}
+GS() {
+    $GREP ${=GREP_ARGS} $@ | sort --numeric-sort | ${=LESS_COLORED}
 }
 alias -g G="| $GREP --color"
-alias grep="$GREP"
 alias gg="git grep "
 # }}}
 
@@ -143,53 +162,29 @@ mailpath=(
     ~/mail/mbox"?Neue Nachrichten in =mbox"
     ~/mail/arbeit"?Neue Nachrichten in =arbeit"
 )
-alias arr="mutt -f =arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
-alias rss="mutt -f =rss"
+alias arr="mutt -f \=arbeit -e 'source ~/.mutt/accounts/stcnet.ru'"
 bindkey -s "\eOP" " inc\n" # F1
 # }}}
 
-# Calculator {{{
-autoload -U zcalc
-alias zc="zcalc"
-# }}}
-
-# Paths {{{
-export CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
-
-export MANPATH=/usr/share/man
-export MANPATH=/usr/local/man:$MANPATH
-export MANPATH=/usr/local/share/man:$MANPATH
-export MANPATH=/usr/share/openssl/man:$MANPATH
-export MANPATH=/usr/local/lib/perl5/site_perl/man:$MANPATH
-export MANPATH=/usr/local/lib/perl5/5.26/perl/man:$MANPATH
-
-export PATH=$HOME/git/bin:$PATH
-export MANPATH=$HOME/git/share/man:$MANPATH
-
-# export PATH=$HOME/postgresql/bin:$PATH
-# export MANPATH=$HOME/postgresql/share/man:$MANPATH
-# [ -e ~/postgresql/lib/libpq.so.5 ] && export LD_PRELOAD=$HOME/postgresql/lib/libpq.so.5
-
-# export PATH=$HOME/texlive/2017/bin/amd64-freebsd:$PATH
-# export INFOPATH=/usr/local/share/info:$HOME/texlive/2017/texmf-dist/doc/info:$INFOPATH
-# export MANPATH=$HOME/texlive/2017/texmf-dist/doc/man:$MANPATH
-
-export PATH=$HOME/stow/bin:$PATH
-export MANPATH=$HOME/stow/share/man:$MANPATH
-export INFOPATH=$HOME/stow/share/info:$INFOPATH
+# Named directories {{{
+. ~/.zhashd
 # }}}
 
 # Completion {{{
 zstyle ":completion:*:functions" ignored-patterns "_*"
 zstyle ":completion:*" matcher-list "" 'm:{a-z\-}={A-Z\_}' 'r:|?=** m:{a-z\-}={A-Z\_}'
-
 _mycomp () {
-    [ $CURRENT -eq 1 ] && _command_names || _files
+    [[ ${words[1]} != man ]] || { _man && return 0 }
+    [[ $CURRENT -eq 1 ]] && _command_names ||  _files && return 0
+    # MAGIC_EQUAL_SUBST {{{
+    [[ $PREFIX = *\=* ]] || return 1
+    compstate[parameter]=${PREFIX%%\=*}
+    compset -P 1 "*="
+    _value
+    # }}}
 }
 zstyle ":completion:*" completer _mycomp _parameters
-
 autoload -U compinit ; compinit -d /tmp/.zcompdump
-
 zstyle ":completion:*:default" list-colors ""
 autoload -U complist
 # }}}
@@ -198,16 +193,28 @@ autoload -U complist
 ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
 . ~/work/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
 typeset -A ZSH_HIGHLIGHT_STYLES
+ZSH_HIGHLIGHT_STYLES[assign]="fg=yellow"
+ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
+ZSH_HIGHLIGHT_STYLES[single-hyphen-option]="fg=green,bold"
+ZSH_HIGHLIGHT_STYLES[double-hyphen-option]="fg=green"
 ZSH_HIGHLIGHT_STYLES[globbing]="fg=magenta"
+ZSH_HIGHLIGHT_STYLES[global-alias]="fg=yellow,bold"
 ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=magenta"
-ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=red"
 ZSH_HIGHLIGHT_STYLES[redirection]="fg=red"
-ZSH_HIGHLIGHT_STYLES[assign]="fg=cyan"
+ZSH_HIGHLIGHT_STYLES[path]="fg=white,underline"
+ZSH_HIGHLIGHT_STYLES[path_pathseparator]="fg=white,bold,underline"
 # }}}
 
 # Autosuggestion {{{
 . ~/work/zsh-autosuggestions/zsh-autosuggestions.zsh
-ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=6"
+ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
 # }}}
 
-~/bin/cleanup.sh
+# fzf {{{
+export FZF_DEFAULT_OPTS="--color=16 --info=inline"
+cf() {
+    local dir=$(find ${1:-.} -mindepth 1 -path "*/\.git" -prune -o -type d -print |
+        fzf --height 40% --reverse --preview="tree -CN {}")
+    [[ -z $dir ]] || cd $dir
+}
+# }}}