dots/zshrc

425 lines
11 KiB
Bash
Raw Normal View History

2008-11-09 15:17:20 -06:00
# .zshrc
# Original, Main author: Saleem Abdulrasool <compnerd@compnerd.org>
# Trivial modifications: David Majnemer
# vim:set nowrap:
autoload -U compinit; compinit -d "${HOME}/.zsh/.zcompdump"
2008-11-09 15:17:20 -06:00
autoload -U age
autoload -U zmv
2008-11-09 15:17:20 -06:00
if [[ ${ZSH_VERSION//.} -gt 420 ]] ; then
autoload -U url-quote-magic
2008-11-09 15:17:20 -06:00
zle -N self-insert url-quote-magic
fi
autoload -U edit-command-line
zle -N edit-command-line
# only alphanumeric chars for moving around
WORDCHARS=''
2008-11-09 15:17:20 -06:00
# disable core dumps
limit coredumpsize 0
# clear on exit
trap clear 0
# shell options
setopt AUTO_CD # directoy command does cd
setopt CORRECT # correct spelling of commands
setopt AUTO_PUSHD # cd uses directory stack
setopt CHASE_DOTS # resolve .. in cd
setopt CHASE_LINKS # resolve symbolic links in cd
setopt CDABLE_VARS # cd var works if $var is a directory
setopt PUSHD_SILENT # make pushd quiet
setopt ALWAYS_TO_END # goto end of word on completion
setopt EXTENDED_GLOB # use zsh globbing extensions
setopt SH_WORD_SPLIT # split non-array variables
setopt BASH_AUTO_LIST # list completions on second tab
setopt LIST_ROWS_FIRST # list completions across
setopt COMPLETE_IN_WORD # completion works inside words
setopt MAGIC_EQUAL_SUBST # special expansion after all =
unsetopt BEEP # stop beeping!
unsetopt LIST_BEEP # seriously, stop beeping!
unsetopt NO_MATCH # dont error on no glob matches
# history
export HISTSIZE=1000
export SAVEHIST=1000
export HISTFILE="${HOME}/.zsh/.history"
setopt SHARE_HISTORY
setopt HIST_IGNORE_SPACE
setopt HIST_REDUCE_BLANKS
setopt INC_APPEND_HISTORY
setopt HIST_IGNORE_ALL_DUPS
unsetopt HIST_BEEP
unsetopt EXTENDED_HISTORY
# colors
if ( which dircolors &> /dev/null ) ; then
eval $(dircolors -b $([ -f /etc/DIR_COLORS ] && echo "/etc/DIR_COLORS"))
elif ( which gdircolors &> /dev/null ) ; then
eval $(gdircolors -b $([ -f /etc/DIR_COLORS ] && echo "/etc/DIR_COLORS"))
fi
# terminal fallback stuff
if (which infocmp &> /dev/null) ; then
case "${TERM}" in
xterm*)
( infocmp $TERM &> /dev/null ) || export TERM=xterm
;;
esac
fi
2008-11-09 15:17:20 -06:00
( which lesspipe &> /dev/null ) && eval $(lesspipe)
export LESS=' -R'
( which less &> /dev/null ) && export PAGER='less'
( which vim &> /dev/null ) && export EDITOR='vim'
2008-11-28 02:13:53 -06:00
export GIT_PAGER=''
2008-11-09 15:17:20 -06:00
# aliases
alias cd..='cd ..'
2008-11-30 22:01:57 -06:00
# handles per OS aliases, fixes a few terms
2008-11-09 15:17:20 -06:00
case `uname -s` in
2008-11-26 00:30:26 -06:00
Linux|CYGWIN*)
2008-11-09 15:17:20 -06:00
alias ls="ls -h --color=auto"
alias grep='grep -d skip --color=auto'
;;
FreeBSD|Darwin|DragonFly)
export LSCOLORS=ExGxFxDxCxDxDxHbaDacec
alias ls="ls -Gh"
alias grep='grep -d skip --color=auto'
;;
Interix)
alias ls="ls --color"
2008-11-30 22:01:57 -06:00
# sorta hacky, but I cannot find a better way to do this :/
if [[ `which infocmp` = /usr/local/bin/infocmp ]] ; then
export TERMINFO=/usr/local/share/terminfo
export TERM=$TERM
fi
;;
2008-11-09 15:17:20 -06:00
SunOS)
if (which gls &> /dev/null) ; then
alias ls="gls -h --color=auto"
else
alias ls="ls -h"
fi
if (which ggrep &> /dev/null) ; then
alias grep='ggrep -d skip --color=auto'
fi
2008-11-25 18:21:49 -06:00
if (which slocate &> /dev/null) ; then
alias locate='slocate'
elif (which glocate &> /dev/null) ; then
alias locate='glocate'
fi
# sorta hacky, but I cannot find a better way to do this :/
if [[ `which infocmp` = /opt/csw/bin/infocmp ]] ; then
export TERMINFO=/opt/csw/share/terminfo
export TERM=$TERM
fi
2008-11-09 15:17:20 -06:00
;;
esac
alias df='df -h'
alias du='du -h'
alias ping='ping -c4'
alias cp='nocorrect cp'
alias mv='nocorrect mv'
alias rm='nocorrect rm -ir'
alias mkdir='nocorrect mkdir'
alias :q='exit'
alias :wq='exit'
( type -p time &> /dev/null ) && alias time='command time'
# keybindings
bindkey -d
bindkey -e
2008-11-09 15:17:20 -06:00
bindkey ' ' magic-space
bindkey -M emacs '\ee' edit-command-line
2008-12-02 20:29:57 -06:00
bindkey -M emacs '^P' history-incremental-search-forward
bindkey -M emacs '^N' history-incremental-search-backward
2008-11-09 15:17:20 -06:00
case $TERM in
xterm*)
2008-12-02 20:29:57 -06:00
bindkey '\e[H' beginning-of-line
bindkey '\e[F' end-of-line
bindkey '\eOH' beginning-of-line
bindkey '\eOF' end-of-line
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
bindkey '\e[7~' beginning-of-line
bindkey '\e[8~' end-of-line
bindkey '\e[3~' delete-char
bindkey '\e[1;5C' emacs-forward-word
bindkey '\e[1;5D' emacs-backward-word
bindkey '\e[5C' emacs-forward-word
bindkey '\e[5D' emacs-backward-word
bindkey '\eOC' emacs-forward-word
bindkey '\eOD' emacs-backward-word
bindkey '\eOc' emacs-forward-word
bindkey '\eOd' emacs-backward-word
bindkey '\e[c' emacs-forward-word
bindkey '\e[d' emacs-backward-word
2008-11-09 15:17:20 -06:00
;;
linux)
2008-12-02 20:29:57 -06:00
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
bindkey '\e[3~' delete-char
2008-11-09 15:17:20 -06:00
;;
rxvt*)
2008-12-02 20:29:57 -06:00
bindkey '\e[c' emacs-forward-word
bindkey '\e[d' emacs-backward-word
bindkey '\eOc' emacs-forward-word
bindkey '\eOd' emacs-backward-word
bindkey '\e[3~' delete-char
bindkey '\e[7~' beginning-of-line
bindkey '\e[8~' end-of-line
2008-11-09 15:17:20 -06:00
;;
2008-11-30 22:01:57 -06:00
cons*)
bindkey '\e[H' beginning-of-line
bindkey '\e[F' end-of-line
2008-11-30 22:01:57 -06:00
bindkey '^?' delete-char
;;
interix)
2008-12-02 20:29:57 -06:00
bindkey '\e[H' beginning-of-line
bindkey '\e[U' end-of-line
2008-11-30 22:01:57 -06:00
bindkey '^?' delete-char
;;
2008-11-30 22:01:57 -06:00
cygwin*)
2008-12-02 20:29:57 -06:00
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
;;
2008-11-09 15:17:20 -06:00
esac
# prompt
if [[ -z ${SSH_TTY} ]] ; then
PROMPT=$'%{\e[01;32m%}%n@%m %{\e[01;34m%}%~ %(?..%{\e[01;31m%})%(!.#.$) %{\e[00;00m%}'
RPROMPT=$'%1(j.%{\e[00;36m%}[%j].)%{\e[01;33m%}[%t]%{\e[00;00m%}'
2008-11-09 15:17:20 -06:00
else
PROMPT=$'%{\e[01;36m%}%n %(?..%{\e[01;31m%})%(!.#.$) %{\e[00;00m%}'
RPROMPT=$'%{\e[01;33m%}%m %{\e[01;32m%}%~%{\e[00;00m%}'
2008-11-09 15:17:20 -06:00
fi
# terminal titles
precmd()
{
local termtitle
termtitle=$(print -P "%n@%m")
title zsh "$termtitle"
}
preexec()
{
# With bits from http://zshwiki.org/home/examples/hardstatus
# emulate -L zsh
local -a cmd; cmd=(${(z)1}) # Re-parse the command line
local termtitle
# Prepend this string to the title.
# termtitle=$(print -P "%(!.-=*[ROOT]*=- | .)%n@%m:")
termtitle=$(print -P "%n@%m:")
case $cmd[1] in
fg)
if (( $#cmd == 1 )); then
# No arguments, must find the current job
# Old approach: cmd=(builtin jobs -l %+)
# weakness: shows a load of bs
title ${jobtexts[${(k)jobstates[(R)*+*]}]%% *} "$termtitle ${jobtexts[${(k)jobstates[(R)*+*]}]}"
elif (( $#cmd == 2 )); then
# Replace the command name, ignore extra args.
# Old approach: cmd=(builtin jobs -l ${(Q)cmd[2]})
# weakness: shows all matching jobs on the title, not just one
title "${jobtexts[${cmd[2]#%}]%% *}" "$termtitle $jobtexts[${cmd[2]#%}]"
else
title "${cmd[2,-1]#%}" "$termtitle ${cmd[2,-1]#%}"
fi
2008-11-26 02:11:10 -06:00
;;
%*)
title "${jobtexts[${cmd[1]#%}]% *}" "$termtitle $jobtexts[${cmd[1]#%}]"
;;
*=*)
shift cmd
;&
exec|sudo)
shift cmd
# If the command is 'exec', drop that, because
# we'd rather just see the command that is being
# exec'd. Note the ;& to fall through the next entry.
2008-11-26 02:11:10 -06:00
;&
*)
title $cmd[1]:t "$termtitle $cmd[*]" # Starting a new job.
2008-11-26 02:11:10 -06:00
;;
esac
}
function title
{
2008-11-26 02:11:10 -06:00
case $TERM in
screen*)
# Use these two for GNU Screen:
print -nR $'\ek'$1$'\e'"\\"
shift
print -nR $'\e_screen \005 | '$*$'\e'"\\"
;;
xterm*|rxvt*|cygwin|interix)
# Use this one instead for everybody else:
2008-11-26 02:11:10 -06:00
shift
print -nR $'\e]0;'$@$'\a'
;;
esac
}
2008-11-09 15:17:20 -06:00
# completion menu
zstyle ':completion:*' menu select=1
# neat-o new features
zstyle ':completion:*' completer _expand _complete _prefix _correct _match _approximate
# don't complete commands that we do not have
2008-11-09 15:17:20 -06:00
zstyle ':completion:*:functions' ignored-patterns '_*'
# group matches
zstyle ':completion:*' group-name ''
zstyle ':completion:*:matches' group 'yes'
# colors on completions
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
# users are all useless, ignore them always
zstyle -e ':completion:*' users "reply=( root '${USERNAME}' )"
# caching good
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path "${HOME}/.zsh/.${HOST}-cache"
# descriptions
zstyle ':completion:*:messages' format $'%{\e[01;35m%} -- %d -- %{\e[00;00m%}'
zstyle ':completion:*:warnings' format $'%{\e[01;31m%} -- No Matches Found -- %{\e[00;00m%}'
zstyle ':completion:*:descriptions' format $'%{\e[01;33m%} -- %d -- %{\e[00;00m%}'
2008-11-09 15:17:20 -06:00
# job numbers
zstyle ':completion:*:jobs' numbers true
2008-11-09 15:17:20 -06:00
# kill/killall menu and general process listing
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:*:kill:*' sort false
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=31;31'
zstyle ':completion:*:*:killall:*' menu yes select
case `uname -s` in
Linux)
zstyle ':completion:*:processes-names' command 'ps -e --no-headers -o args'
;;
FreeBSD|Interix|OpenBSD|SunOS)
zstyle ':completion:*:processes-names' command 'ps -e -o args | awk "NR != 1"'
;;
Darwin)
if [[ $(sw_vers -productVersion) > 10.4 ]] ; then
2008-11-09 15:17:20 -06:00
zstyle ':completion:*:processes-names' command 'ps -e -o command | awk "NR != 1"'
else
zstyle ':completion:*:processes-names' command 'ps -A -o command | awk "NR != 1"'
fi
;;
2008-11-26 00:30:26 -06:00
CYGWIN*)
zstyle ':completion:*:processes-names' command 'ps -e -s | awk "NR != 1"'
;;
2008-11-09 15:17:20 -06:00
esac
case `uname -s` in
2008-11-13 18:52:48 -06:00
Linux)
2008-11-09 15:17:20 -06:00
zstyle ':completion:*:*:kill:*:processes' command 'ps --forest -U '${USERNAME}' -o pid,args | sed "/ps --forest -U '${USERNAME}' -o pid,args/d"'
;;
2008-11-13 18:52:48 -06:00
Interix)
zstyle ':completion:*:*:kill:*:processes' command 'ps -i -U '${USERNAME}' -o pid,args | sed "/ps -i -U '${USERNAME}' -o pid,args/d"'
;;
2008-11-26 00:30:26 -06:00
CYGWIN*)
zstyle ':completion:*:*:kill:*:processes' command 'ps -u '${USERNAME}' -s | sed "/ps -u '${USERNAME}' -s/d"'
;;
SunOS|FreeBSD|OpenBSD)
2008-11-13 18:52:48 -06:00
zstyle ':completion:*:*:kill:*:processes' command 'ps -U '${USERNAME}' -o pid,args | sed "/ps -U '${USERNAME}' -o pid,args/d"'
;;
2008-11-09 15:17:20 -06:00
Darwin)
zstyle ':completion:*:*:kill:*:processes' command 'ps -U '${USERNAME}' -o pid,command | sed "/ps -U '${USERNAME}' -o pid,command/d"'
;;
esac
case `uname -s` in
Interix|SunOS|FreeBSD|Linux)
zstyle ':completion:*:*:killall:*:processes-names' command "ps -U '${USERNAME}' -o comm"
;;
2008-11-26 00:30:26 -06:00
CYGWIN*)
zstyle ':completion:*:*:killall:*:processes-names' command "ps -u '${USERNAME}' -s"
;;
2008-11-09 15:17:20 -06:00
Darwin)
if [[ $(sw_vers -productVersion) > 10.4 ]] ; then
2008-11-09 15:17:20 -06:00
zstyle ':completion:*:*:killall:*:processes-names' command "ps -U '${USERNAME}' -o comm"
else
zstyle ':completion:*:*:killall:*:processes-names' command "ps -U '${USERNAME}' -o command"
fi
;;
OpenBSD)
zstyle ':completion:*:*:killall:*:processes-names' command "ps -U '${USERNAME}' -o command"
;;
esac
# case insensitivity, partial matching, substitution
zstyle ':completion:*' matcher-list 'm:{A-Z}={a-z}' 'm:{a-z}={A-Z}' 'r:|[-._]=* r:|=*' 'l:|=* r:|=*' '+l:|=*'
# compctl should die
zstyle ':completion:*' use-compctl false
# dont suggest the first parameter again
zstyle ':completion:*:ls:*' ignore-line yes
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:scp:*' ignore-line yes
zstyle ':completion:*:diff:*' ignore-line yes
# Keep track of other people accessing the box
watch=( all )
export LOGCHECK=30
2008-11-25 23:14:07 -06:00
export WATCHFMT=$'\e[01;36m'" -- %n@%m has %(a.Logged In.Logged out) --"$'\e[00;00m'
2008-11-09 15:17:20 -06:00
# directory hashes
if [[ -d "${HOME}/sandbox" ]] ; then
hash -d sandbox="${HOME}/sandbox"
2008-11-09 15:17:20 -06:00
fi
if [[ -d "${HOME}/work" ]] ; then
hash -d work="${HOME}/work"
2008-11-09 15:17:20 -06:00
for dir in "${HOME}"/work/*(N-/) ; do
hash -d $(basename "${dir}")="${dir}"
done
2008-11-09 15:17:20 -06:00
fi
# extras
if [[ -d "${HOME}/.zsh" ]] ; then
for file in "${HOME}"/.zsh/*(N.x:t) ; do
source "${HOME}/.zsh/${file}"
done
2008-11-09 15:17:20 -06:00
fi