.zshrc 8.95 KB
Newer Older
1 2 3
#------------------------------------------------------------------#
# Completions
#------------------------------------------------------------------#
Hund's avatar
Hund committed
4

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# Colors
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}

# Kill completion
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*'   force-list always

zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*'   force-list always

# For autocompletion with an arrow-key driven interface
zstyle ':completion:*' menu select

# Autocompletion of command line switches for aliases
#setopt complete_aliases # Brakes completion for aliases like ps (pacman -S)
Hund's avatar
Hund committed
23

Hund's avatar
Hund committed
24 25 26
# zsh-completions
fpath=($HOME/Git/zsh-completions/src $fpath)
fpath=($HOME/.zsh/completions/ $fpath)
Hund's avatar
Hund committed
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
# Case insensitive completion
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'

# Organize completions by categories
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*' format $'\n%F{yellow}Completing %d%f\n'
zstyle ':completion:*' group-name ''

# Respect multibyte characters when found in strings
unsetopt MULTIBYTE

# Quote pasted URLs
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic

# When new programs is installed, auto update autocomplete without reloading shell
zstyle ':completion:*' rehash true

# Don't prompt for a huge list, page it!
zstyle ':completion:*:default' list-prompt '%S%M matches%s'

# No need for 'cd'
setopt autocd

# Group symlinks with folders first using ls
# ls -ldU -- *(o+dir1st)
dir1st() { [[ -d $REPLY ]] && REPLY=1-$REPLY || REPLY=2-$REPLY;}

# Edit command line with $EDITOR
autoload -U edit-command-line

# Copy current command to clipboard (Ctrl+X)
zle -N copyx; copyx() { echo -E $BUFFER | xsel -ib }; bindkey '^X' copyx
Hund's avatar
Hund committed
63

64 65 66
#------------------------------------------------------------------#
# Set distro variable
#------------------------------------------------------------------#
67

Hund's avatar
Hund committed
68
distro=$(cat /etc/*-release | grep --color=NEVER -w 'ID' | cut -c4-)
Hund's avatar
Hund committed
69

70 71 72
#------------------------------------------------------------------#
# Variables
#------------------------------------------------------------------#
73

74 75 76 77 78 79 80 81 82
export SHELL="/bin/zsh"
export TERMINAL="rxvt-256color"
export EDITOR="vim"
export BROWSER="qutebrowser"
export LC_ALL=en_US.UTF-8
export LC_TIME=sv_SE.UTF-8
export LANG=en_US.UTF-8
#export LANGUAGE=en_US.UTF-8
#export ZLS_COLORS=$LS_COLORS
83
export XDG_CONFIG_HOME="$HOME/.config"
84 85 86 87
export PATH="$HOME/Scripts/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/Scripts:$PATH"
export FREETYPE_PROPERTIES="truetype:interpreter-version=35"
88 89 90 91 92 93 94

# Ruby
if [ "$distro" = "gentoo" ] || [ "$distro" = "arch" ]; then
  #export PATH="$HOME/.gem/ruby/2.2.0/bin:$PATH"
  export PATH="$(ruby -e 'print Gem.user_dir')/bin:$PATH"
  export GEM_HOME="$(ruby -e 'print Gem.user_dir')"
fi
Hund's avatar
Hund committed
95

96
#------------------------------------------------------------------#
Hund's avatar
Hund committed
97
# History
98
#------------------------------------------------------------------#
99

Hund's avatar
Hund committed
100
HISTFILE=~/.zsh/history
Hund's avatar
Hund committed
101
# Amount of history to keep
102
SAVEHIST=5000
Hund's avatar
Hund committed
103 104
# And how much of that history zsh should read at start
HISTSIZE=5000
105 106 107 108

# Ignore duplicate history
setopt hist_ignore_all_dups
setopt hist_save_no_dups
Hund's avatar
Hund committed
109

Hund's avatar
Hund committed
110 111 112
# No history if command starts with space
setopt histignorespace

113 114 115 116 117 118 119 120 121 122 123 124 125
# History search
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
[[ -n "$key[Up]"   ]] && bindkey -- "$key[Up]"   up-line-or-beginning-search
[[ -n "$key[Down]" ]] && bindkey -- "$key[Down]" down-line-or-beginning-search

# Better history behavior (acts the same as vim)
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "\e[A" history-beginning-search-backward-end
bindkey "\e[B" history-beginning-search-forward-end
Hund's avatar
Hund committed
126

Hund's avatar
Hund committed
127
# History Vi-like search 
128 129
bindkey -M vicmd l history-search-backward
bindkey -M vicmd k history-search-forward
130 131 132
bindkey -M vicmd / history-incremental-search-backward
bindkey -M vicmd n history-incremental-search-backward
bindkey -M vicmd N history-incremental-search-forward
133 134
bindkey -M vicmd l history-beginning-search-backward
bindkey -M vicmd k history-beginning-search-forward
Hund's avatar
Hund committed
135

136 137 138
#------------------------------------------------------------------#
# Promt 
#------------------------------------------------------------------#
139 140 141

# <name> at <host> in <dir>
# >>
Hund's avatar
Hund committed
142
PS1=$'%{\e[0;34m%}%n %{\e[0m%}at %{\e[0;33m%}%M %{\e[0m%}in %{\e[0;35m%}%~ 
143
%{\e[0m%}>> '
Hund's avatar
Hund committed
144

145 146 147
#------------------------------------------------------------------#
# Colors
#------------------------------------------------------------------#
148

149
autoload -U colors && colors
150

151
# Dircolors
152
eval $(dircolors -b $HOME/.zsh/dircolors/solarized-hund.256dark)
153

154 155 156
#------------------------------------------------------------------#
# Keychain
#------------------------------------------------------------------#
157

Hund's avatar
Hund committed
158 159 160
if [ "$HOST" = "Atlas" ]; then
  eval $(keychain --eval --noask --nogui --quiet --agents ssh id_rsa_fjuppen)
fi
Hund's avatar
Hund committed
161

162 163 164
#------------------------------------------------------------------#
# Vi mode
#------------------------------------------------------------------#
165

166
zle -N edit-command-line
Hund's avatar
Hund committed
167
bindkey -M vicmd '^V' edit-command-line
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
# Enable Vi mode for zsh
bindkey -v
# no delay entering normal mode
# https://coderwall.com/p/h63etq
# https://github.com/pda/dotzsh/blob/master/keyboard.zsh#L10
# 10ms for key sequences
KEYTIMEOUT=1
# show vim status
# http://zshwiki.org/home/examples/zlewidgets
function zle-line-init zle-keymap-select {
    RPS1="${${KEYMAP/vicmd/-- NORMAL --}/(main|viins)/-- INSERT --}"
    RPS2=$RPS1
    zle reset-prompt
}
zle -N zle-line-init
zle -N zle-keymap-select
# add missing vim hotkeys
# http://zshwiki.org/home/zle/vi-mode
bindkey -a u undo
bindkey -a '^T' redo
bindkey '^?' backward-delete-char  #backspace
# history search in vim mode
# http://zshwiki.org./home/zle/bindkeys#why_isn_t_control-r_working_anymore
# ctrl+r to search history
bindkey -M viins '^r' history-incremental-search-backward
bindkey -M vicmd '^r' history-incremental-search-backward
Hund's avatar
Hund committed
194

195 196 197 198 199 200 201 202 203 204 205 206 207
# Functional home/end/delete/insert keys
bindkey '\e[1~'   beginning-of-line  # Linux console
bindkey '\e[H'    beginning-of-line  # xterm
bindkey '\eOH'    beginning-of-line  # gnome-terminal
bindkey '\e[2~'   overwrite-mode     # Linux console, xterm, gnome-terminal
bindkey '\e[3~'   delete-char        # Linux console, xterm, gnome-terminal
bindkey '\e[4~'   end-of-line        # Linux console
bindkey '\e[F'    end-of-line        # xterm
bindkey '\eOF'    end-of-line        # gnome-terminal

#------------------------------------------------------------------#
# Git
#------------------------------------------------------------------#
208 209 210

# Needed for dynamic windows titles
#autoload -Uz vcs_info 
211 212 213 214

#------------------------------------------------------------------#
# Dynamic window title
#------------------------------------------------------------------#
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

#case $TERM in
#  termite|*xterm*|rxvt|rxvt-unicode|rxvt-256color|rxvt-unicode-256color|st-256colors|(dt|k|E)term)
#    precmd () {
#      vcs_info
#      print -Pn "\e]0;%n at %M in %~\a"
#    } 
##    preexec () { print -Pn "\e]0;%n at %M in %~ >> $1\a" }
#    preexec () { print -Pn "\e]0;$1\a" }
#    ;;
#  screen|screen-256color)
#    precmd () { 
#      vcs_info
#      print -Pn "\e]83;title \"$1\"\a" 
#      print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~]\a" 
#    }
#    preexec () { 
#      print -Pn "\e]83;title \"$1\"\a" 
#      print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~] ($1)\a" 
#    }
#    ;; 
#esac
237 238 239 240

#------------------------------------------------------------------#
# Fixes
#------------------------------------------------------------------#
241

Hund's avatar
Hund committed
242 243 244
# Prevent Screen from freezing when using Ctrl-S/Q in rTorrent
stty ixany
stty ixoff -ixon
245 246 247 248 249 250

# Command completion
# This part needs to be last for the t completion to work
autoload -Uz compinit
compinit

251 252 253
#------------------------------------------------------------------#
# Distro specific things
#------------------------------------------------------------------#
254

255
# Arch Linux
Hund's avatar
Hund committed
256
if [ "$distro" = "arch" ]; then
257 258 259 260 261
  # Pacman
  zstyle ':completion:*:pacman:*' force-list always
  zstyle ':completion:*:*:pacman:*' menu yes select
fi

Hund's avatar
Hund committed
262 263 264
#------------------------------------------------------------------#
# Load in additional files
#------------------------------------------------------------------#
265

Hund's avatar
Hund committed
266 267 268 269 270
source "$HOME/.zsh/alias"
source "$HOME/.zsh/functions"
source "$HOME/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh"
source "$HOME/.zsh/plugins/h.sh"
source "$HOME/.zsh/plugins/t-completion.zsh"
271 272 273 274 275 276 277 278

# Autojump
if [ "$distro" = "arch" ]; then
  source "/etc/profile.d/autojump.zsh"
fi
if [ "$distro" = "debian" ] || [ "$distro" = "gentoo" ]; then
  source "/usr/share/autojump/autojump.zsh"
fi
Hund's avatar
Hund committed
279

280
# vim: set ts=2 sw=2 et: