Please bear with us as we work to restore functionality to dotfiles.org.
Extracted from my configuration and stripped off local settings. I drew quite a few tricks from _why but still have a few places left for improvement. Contains mostly small tweaks for navigating around since I don't do much more in my shell.
setopt interactivecomments
setopt noclobber # non-destructive redirection
autoload colors # color macros
autoload -Uz compinit
compinit
ZSHDIR=~/.zsh
bindkey -e # vi's keybindings are just too magic for a shell
# set variable debian_chroot if running in a chroot with /etc/debian_chroot
if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# prepare the environment
typeset -Ux PYTHONPATH=~/svn:$PYTHONPATH
typeset -Ux PATH=~/bin:$PATH
typeset -Ux EDITOR=vim
# insert unicode character (ctrl-u hexcode ctrl-u)
autoload insert-unicode-char
zle -N insert-unicode-char
bindkey '^u' insert-unicode-char
# completion caching
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
setopt hashlist_all
# abbreviation expansion
typeset -Ag abbrev
abbrev=(
#'key' 'value'
)
magic-abbrev-expand() {
local MATCH
LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
LBUFFER+=${abbrev[$MATCH]:-$MATCH}
zle self-insert
}
no-magic-abbrev-expand() {
LBUFFER+=' '
}
zle -N magic-abbrev-expand
zle -N no-magic-abbrev-expand
bindkey " " magic-abbrev-expand
bindkey "^x " no-magic-abbrev-expand
# completing PIDs with menu selection
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
# in-word completion
bindkey '^i' expand-or-complete-prefix
# always use the menu
zstyle ':completion:*' menu select=0 select=long-list
# expand ... automatically to ../..
rationalise-dot() {
if [[ $LBUFFER = *.. ]]; then
LBUFFER+=/..
else
LBUFFER+=.
fi
}
zle -N rationalise-dot
bindkey . rationalise-dot
# navigation shortcuts and tweaks
alias cd..="cd .."
alias dop="cd ~/Desktop/"
setopt autocd # non-commands are cd'ed to
setopt autopushd pushd_ignoredups pushd_silent
setopt listpacked # tighter completion display
setopt noautoremoveslash # leave slashes in place
function _popd {
unsetopt print_exit_value
popd -q 2>/dev/null
setopt print_exit_value
chpwd
zle -I
}
zle -N _popd
bindkey '^[[1;3D' _popd
# history settings
autoload history-search-end # history search navigates to EOL
HISTFILE=~/.histfile
HISTSIZE=5000
SAVEHIST=20000
setopt appendhistory inc_appendhistory
setopt hist_findnodups hist_ignoredups
# url escaping
if autoload -U url-quote-magic ; then
zle -N self-insert url-quote-magic
zstyle ':url-quote-magic:*' url-metas '*?[]^()~#{}='
fi
# job control
bindkey -s '^z' "fg\n" # ^z continues as well
setopt longlistjobs # display PID on suspend
setopt notify # report background job events immediately
setopt print_exit_value # report job status changes
setopt checkjobs # report job status on shell exit
# prompt
typeset PROMPT="${debian_chroot:+\[$debian_chroot\] }%v%(!.#.$) "
typeset RPROMPT="%(1j.%j:.)%n@%m"
setopt transient_rprompt # remove right prompt when accepting command line
setopt promptsubst # apply substitutions in prompts
# client detection
function isyakuake {
[ "$DCOP_YAKUAKE_SESSION" ] && return 0
return 1
}
# low-level title interface
function _title() {
print -Pn "\e]2;$*\a";
}
function _yakuake() {
dcop yakuake DCOPInterface slotRenameSession $DCOP_YAKUAKE_SESSION $(print -Pn "$*")
}
# title
function title() {
if isyakuake; then
_yakuake "$1"
else
_title "$1"
fi
}
function longtitle() {
if isyakuake; then
_title "$1"
else
return
fi
}
# events
function precmd() {
title "$PSVAR"
longtitle "%n@%M: %d"
}
function preexec() {
longtitle "%D{%H%M.%S:} $1"
}
function chpwd() {
PSVAR=${(S)${(S)${(S)${(S)$(print -Pn %~)/#\/www\//@}/#\~\/sandbox\//_}/#\~\/sandbox/sandbox}/#\~\/svn\//\&}
}
chpwd # set $PSVAR initially
function zshexit() {
if isyakuake; then _title "Shell"; fi
}
# colors
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias rgrep='rgrep --color=auto'
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# security measures
alias cp="cp -i"
alias mv="mv -i"
# sandbox
local sandbox=~/sandbox
function sandbox() {
local dir=$sandbox/$1
mkdir -p "$dir"
cd "$dir"
if [ $# -gt 1 ]; then
${EDITOR:-vim} $argv[2,-1]
fi
}
alias ndbox=sandbox
local _sandbox_safe=$(echo "$sandbox"|sed "s/\//\\\\\//g")
_sandbox_comp() {
zle -U $* "$1"
if [ $CURRENT -eq 2 ]; then
# ~/sandbox/*
compadd $(ls -1p "$sandbox"|grep /|map basename)
compadd .
elif [ $CURRENT -ge 3 ]; then
# ~/sandbox/$2/*
dir=$words[2]
compadd $(find "$sandbox/$dir"|sed -r "s/^$_sandbox_safe\/$dir\/?//")
fi
}
compdef _sandbox_comp sandbox