summary refs log tree commit diff stats
path: root/zsh/zshrc
diff options
context:
space:
mode:
authorAlan Pearce2013-04-28 20:54:18 +0100
committerAlan Pearce2013-04-28 20:54:18 +0100
commite7657d6ba54ad5714657cff9be86ec416d342a4c (patch)
tree50a2fada14e8d5f76ef890c4b860fbdd4faf812f /zsh/zshrc
parent6bec14c2d18c915a3510aba36a37e78a8b83170f (diff)
downloaddotfiles-e7657d6ba54ad5714657cff9be86ec416d342a4c.tar.lz
dotfiles-e7657d6ba54ad5714657cff9be86ec416d342a4c.tar.zst
dotfiles-e7657d6ba54ad5714657cff9be86ec416d342a4c.zip
Migrate repository from mercurial without history
Diffstat (limited to 'zsh/zshrc')
-rwxr-xr-xzsh/zshrc367
1 files changed, 367 insertions, 0 deletions
diff --git a/zsh/zshrc b/zsh/zshrc
new file mode 100755
index 0000000..7d8915b
--- /dev/null
+++ b/zsh/zshrc
@@ -0,0 +1,367 @@
+#!/usr/bin/env zsh
+#
+# System variables
+#
+
+if [[ $defpath == ""  && -d ~/bin ]]
+then
+	defpath=($path)
+	path=(
+		$defpath
+		~/bin
+	)
+fi
+
+if [[ ! -d ~/.zsh/cache ]]
+then
+	mkdir -p ~/.zsh/cache
+fi
+
+myfuncs=( ~alan/dotfiles/zsh/functions/*(/) )
+fpath=(
+	$myfuncs
+	~alan/dotfiles/zsh/completion/
+	$fpath
+)
+
+export PATH
+export PAGER="less"
+export CLICOLOR=true
+
+#
+# zsh variables
+#
+HISTFILE=~/.zsh/history
+HISTSIZE=4000
+SAVEHIST=3000
+
+WORDCHARS='*?_-[]~=.&;!#$%^(){}<>'
+
+#If a command takes more than 5 seconds, give statistics
+REPORTTIME=5
+TIMEFMT="%U user %S system %P cpu %*Es total"
+
+#Check for user logins
+watch=notme
+WATCHFMT="%n has %a %l from %M at %t"
+
+hosts=(
+	server
+	prefect
+	alanpearce.co.uk
+	home.alanpearce.co.uk
+	lethalrocks.uk.to
+	alphapulsar.uk.to
+	st.alphapulsar.uk.to
+	a.st.alphapulsar.uk.to
+	st
+)
+
+users=(alan root toor)
+
+function linkAuthSock () {
+	local linkSock=~/.ssh/ssh_auth_sock
+	ln -sf $1  ~/.ssh/ssh_auth_sock
+	export SSH_AUTH_SOCK=$linkSock
+}
+
+if [[ "$SSH_AUTH_SOCK" != "" ]]
+then
+	if [[ -e ~/.ssh/ssh_auth_sock && ! -L ~/.ssh/ssh_auth_sock ]]
+	then
+		linkAuthSock $SSH_AUTH_SOCK
+	fi
+fi
+
+if [[ "$OSTYPE" == *gnu* ]]
+then
+	eval `dircolors -b` #exports LSCOLORS
+	ls_options="-v --group-directories-first --color=auto"
+	ls_isodate="--time-style=long-iso"
+elif [[ "$OSTYPE" == freebsd* ]]
+then
+	freebsd=1
+	ls_options="-p"
+	ls_isodate="-D '%F %k:%M'"
+fi
+
+#Ignore suffixes in completion
+fignore=(
+    svbin
+)
+
+#
+# Modules
+#
+autoload -Uz compinit bashcompinit
+autoload -U colors complist zrecompile zmv zargs zed
+autoload -Uz vcs_info
+autoload insert-files
+zle -N insert-files
+zmodload -i zsh/complist
+colors
+compinit -d .zsh/cache/compdump
+bashcompinit
+
+zstyle :compinstall filename '/home/alan/.zshrc'
+
+autoload -Uz _tmux_pane_words
+zle -C tmux-pane-words-prefix   complete-word _generic
+zle -C tmux-pane-words-anywhere complete-word _generic
+zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words
+zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current
+zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}'
+
+# Speed up completion by not going further than a full match
+zstyle ':completion:*' accept-exact '*(N)'
+
+zstyle ':completion:*:default' use-cache on
+zstyle ':completion:*:default' cache-path ~/.zsh/cache/compcache
+
+zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' '+m:{A-Z}={a-z}'
+zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _match
+
+zstyle ':completion:*'              verbose    yes
+zstyle ':completion:*:messages'     format     '%d'
+zstyle ':completion:*:warnings'     format     'No   matches  for: %d'
+zstyle ':completion:*:descriptions' format     '%U%B%d%b%u'
+zstyle ':completion:*:corrections'  format     '%B%d (errors: %e)%b'
+zstyle ':completion:*'              group-name ''
+
+# Complete all user processes
+zstyle ':completion:*:processes' command 'ps -au$USER'
+# Add colour to process lists
+zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
+zstyle ':completion:*:*:kill:*'           menu        yes    select
+zstyle ':completion:*:kill:*'             force-list  always
+zstyle ':completion:*:*:killall:*'        menu        yes    select
+zstyle ':completion:*:killall:*'          force-list  always
+
+# Complete unreadable log filenames
+#zstyle ':completion::complete:(most|tail)::' fake-files '/var/log/*:current'
+
+# Group manpages by section
+zstyle ':completion:*' separate-sections true
+
+# Users
+#zstyle '*' users $users
+
+zstyle '*' hosts $hosts
+
+zstyle ':completion:*:functions' ignored-patterns '_*'
+zstyle ':completion:*:cd:*'	     ignore-parents parent pwd
+
+#This works, but isn't the same as ls
+#zstyle ':completion:*:default' list-colors ''
+zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
+
+zstyle ':vcs_info:*' enable git hg
+
+# Filename suffixes to ignore during completion (except after rm command)
+zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' '*?.old' '*?.pro'
+
+## Prompt
+if [[ $term = "putty" ]];then
+	prompt_char="›"
+else
+	prompt_char=">"
+fi
+
+PS1="%B%~%(!.%{$fg[red]%}.%{$fg[green]%})$prompt_char%f%b "
+
+# Options
+
+# Changing directories
+setopt auto_cd
+
+# Completion
+setopt auto_list # List multiple choices on first tab
+unsetopt list_ambiguous # List ambiguous choices rather than completing common prefixes
+unsetopt list_beep # Don't try to beep here
+setopt list_types # Indicate file types
+
+# Expansion and globbing
+setopt extended_glob # Use #~^ as part of filename patterns
+unsetopt nomatch
+
+# History
+unsetopt hist_beep
+setopt hist_expire_dups_first
+setopt hist_fcntl_lock # Use standard locking on histfile
+setopt hist_find_no_dups
+setopt hist_ignore_space
+setopt hist_reduce_blanks
+setopt hist_verify
+setopt inc_append_history
+
+# Input/Output
+unsetopt clobber
+unsetopt flow_control
+setopt path_dirs # Search PATH even with slashes
+setopt print_exit_value
+
+# Job Control
+setopt auto_continue
+unsetopt nohup
+setopt long_list_jobs
+unsetopt notify
+
+# Scripts and functions
+unsetopt multi_func_def
+setopt multios
+
+# Zle
+unsetopt beep
+
+############
+# Keybinds #
+############
+#KiTTY
+bindkey "OD"    backward-word
+bindkey "OC"    forward-word
+
+#General
+bindkey "[1~"   beginning-of-line
+bindkey "[4~"   end-of-line
+bindkey "[5~"   beginning-of-history
+bindkey "[6~"   end-of-history
+bindkey "[2~"   quoted-insert
+bindkey "[3~"   delete-char
+
+bindkey ''      backward-delete-char
+
+bindkey '^I'      expand-or-complete-prefix
+bindkey ''    reverse-menu-complete
+bindkey ''    up-line-or-search
+bindkey ''    down-line-or-search
+
+#urxvt
+bindkey '[3;5~' delete-word
+bindkey '' backward-word
+bindkey '' forward-word
+
+bindkey 'f'	  insert-files
+bindkey 'd'     describe-key-briefly
+
+bindkey '\'	  tmux-pane-words-prefix
+bindkey '|'	  tmux-pane-words-anywhere
+
+# Aliases before functions
+alias getcflags='gcc -\#\#\# -march=native -E /usr/include/stdlib.h 2>&1 | grep "/usr/libexec/gcc/.*cc1"'
+alias grep='grep --color=auto'
+alias df='df -h'
+alias du='du -h'
+alias md='mkdir -p'
+alias rd='rmdir'
+alias .='source'
+
+alias l="\ls ${ls_options} -Bp"
+alias l1="\ls ${ls_options} -1"
+alias ls="\ls ${ls_options} -hF"
+alias la="\ls ${ls_options} -hA"
+alias ll="\ls ${ls_options} ${ls_isodate} -hl"
+alias lal="ll -A"
+alias lla="lal"
+alias llr="ll -t"
+alias gpp='g++'
+alias lsr="ls -tld *(m-2)" # mtime < -2days
+
+alias trans="transmission-remote transmission.home"
+alias bitcoin="bitcoind"
+alias namecoin="~alan/applications/namecoin/src/namecoind"
+alias e="$EDITOR"
+alias E="SUDO_EDITOR=\emacsclient -c -a emacs\" sudoedit"
+alias aticonfig="DISPLAY=:0 \aticonfig"
+alias wprop="xprop | egrep WM_(CLASS|NAME|WINDOW_ROLE|TYPE)"
+
+alias -g ...='../..'
+
+#Suffix aliases
+alias -s log=less
+
+if [[ -e =hub ]]; then
+	alias git="hub"
+fi
+
+# Functions
+
+precmd () {
+    [[ -t 1 ]] || return
+    case $TERM in
+		*xterm*|rxvt|putty|(dt|k|E)term|screen*) print -Pn "\e]2;%~\a"
+		;;
+	esac
+}
+
+pid () {
+    local i
+    for i in /proc/<->/stat
+    [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t
+    return 0
+}
+
+_force_rehash() {
+    (( CURRENT == 1 )) && rehash
+    return 1        # Because we didn't really complete anything
+}
+
+portgrep() {
+    sudo lsof -i :$1 -nP | egrep '(LISTEN|UDP|COMMAND)'
+}
+
+ipgrep() {
+    sudo lsof -i @$1 -nP
+}
+
+smart_sudo () {
+    if [[ -n $1 ]]; then
+        \sudo $argv
+    else
+        #if no parameters were given, then assume we want a root shell
+        \sudo -i -u toor
+    fi
+}
+
+compdef _sudo smart_sudo
+
+smart_compile () {
+	local zcompargs
+	if [[ $1 = *zshrc* ]]; then
+		zcompargs="-R"
+	fi
+
+	if [[ $EUID -ne 0 || $1 != *alan* ]]; then
+		zrecompile -q -p $zcompargs $1
+	fi
+	if [[ -n $2 ]]; then
+		. $1
+	fi
+}
+
+host=${HOST%%.*}
+if [[ -e ~alan/dotfiles/zsh/zshrc_$host ]]; then
+	# Don't recompile as toor|root
+	smart_compile ~alan/dotfiles/zsh/zshrc_$host 1
+fi
+if [[ -e /usr/bin/emerge ]]; then
+	smart_compile ~alan/dotfiles/zsh/zshrc_gentoo 1
+elif [[ $freebsd -eq 1 ]]; then
+	smart_compile ~alan/dotfiles/zsh/zshrc_freebsd 1
+fi
+
+for fp in $myfuncs; do
+	zrecompile -p $fp $fp/*
+done
+
+_FASD_DATA="$HOME/.zsh/fasd-data"
+fasd_cache="$HOME/.zsh/cache/fasd-init-zsh"
+autoload -U fasd
+if [[ ! -s "$fasd_cache" || ~alan/dotfiles/zsh/functions/fasd -nt "$fasd_cache" ]]; then
+	fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install >! "$fasd_cache"
+fi
+smart_compile "$fasd_cache" 1
+unset fasd_cache
+alias e="f -e $EDITOR"
+
+smart_compile ~/.zshrc
+alias s="smart_sudo "