###########################################################
# Options for zsh
export PATH="/home/sini/.cw/def:$PATH"
export CW_COLORIZE=grey
export HISTFILE=~/.zsh_history
export HISTSIZE=500
export SAVEHIST=50000
autoload -U compinit
compinit
setopt autopushd pushdminus pushdsilent pushdtohome
setopt autocd
setopt cdablevars
#setopt ignoreeof
setopt interactivecomments
setopt nobanghist
setopt noclobber
setopt HIST_REDUCE_BLANKS
setopt HIST_IGNORE_SPACE
setopt SH_WORD_SPLIT
setopt nohup
setopt complete_in_word
setopt always_to_end # When complete from middle, move cursor
setopt correct # Spelling correction
setopt extended_history
function title {
if [[ $TERM == "screen" ]]; then
# Use these two for GNU Screen:
print -nR $'\033k'$1$'\033'\\\
print -nR $'\033]0;'$2$'\a'
elif [[ $TERM == "xterm" || $TERM == "rxvt" || $TERM == "rxvt-unicode" || $TERM == "xterm-color" ]]; then
# Use this one instead for XTerms:
print -nR $'\033]0;'$*$'\a'
fi
}
function precmd {
title zsh "$PWD"
}
preexec() {
emulate -L zsh
local -a cmd; cmd=(${(z)1}) # Re-parse the command line
# Construct a command that will output the desired job number.
case $cmd[1] in
fg)
if (( $#cmd == 1 )); then
# No arguments, must find the current job
cmd=(builtin jobs -l %+)
else
# Replace the command name, ignore extra args.
cmd=(builtin jobs -l ${(Q)cmd[2]})
fi;;
%*) cmd=(builtin jobs -l ${(Q)cmd[1]});; # Same as "else" above
exec) 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.
*) title $cmd[1]:t "$cmd[2,-1]" # Not resuming a job,
return;; # so we're all done
esac
local -A jt; jt=(${(kv)jobtexts}) # Copy jobtexts for subshell
# Run the command, read its output, and look up the jobtext.
# Could parse $rest here, but $jobtexts (via $jt) is easier.
$cmd >>(read num rest
cmd=(${(z)${(e):-\$jt$num}})
title $cmd[1]:t "$cmd[2,-1]") 2>/dev/null
}
extract_archive () {
local old_dirs current_dirs lower
lower=${(L)1}
old_dirs=( *(N/) )
if [[ $lower == *.tar.gz || $lower == *.tgz ]]; then
tar zxfv $1
elif [[ $lower == *.gz ]]; then
gunzip $1
elif [[ $lower == *.tar.bz2 || $lower == *.tbz ]]; then
bunzip2 -c $1 | tar xfv -
elif [[ $lower == *.bz2 ]]; then
bunzip2 $1
elif [[ $lower == *.zip ]]; then
unzip $1
elif [[ $lower == *.rar ]]; then
unrar e $1
elif [[ $lower == *.tar ]]; then
tar xfv $1
elif [[ $lower == *.lha ]]; then
lha e $1
else
print "Unknown archive type: $1"
return 1
fi
# Change in to the newly created directory, and
# list the directory contents, if there is one.
current_dirs=( *(N/) )
for i in {1..${#current_dirs}}; do
if [[ $current_dirs[$i] != $old_dirs[$i] ]]; then
cd $current_dirs[$i]
ls
break
fi
done
}
alias ex=extract_archive
compdef '_files -g "*.gz *.tgz *.bz2 *.tbz *.zip *.rar *.tar *.lha"' extract_archive
# PS1 and PS2
export PS1="$(print '%{\e[1;34m%}%n%{\e[0m%}'):$(print '%{\e[0;34m%}%~%{\e[0m%}')$ "
export PS2="$(print '%{\e[0;34m%}>%{\e[0m%}')"
# Vars used later on by zsh
export EDITOR="vim"
export XTERM="urxvt"
##################################################################
# Stuff to make my life easier
# allow approximate
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric
# tab completion for PID :D
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
# cd not select parent dir.
zstyle ':completion:*:cd:*' ignore-parents parent pwd
zstyle ':completion::complete:*' use-cache 1
##################################################################
# Key bindings
# http://mundy.yazzy.org/unix/zsh.php
# http://www.zsh.org/mla/users/2000/msg00727.html
typeset -g -A key
bindkey -e
bindkey '\e[3~' delete-char
bindkey '^R' history-incremental-search-backward
bindkey '^?' backward-delete-char
bindkey '^[[1~' beginning-of-line
bindkey '^[[5~' up-line-or-history
bindkey '^[[3~' delete-char
bindkey '^[[4~' end-of-line
bindkey '^[[6~' down-line-or-history
bindkey '^[[A' up-line-or-search
bindkey '^[[D' backward-char
bindkey '^[[B' down-line-or-search
bindkey '^[[C' forward-char
##################################################################
# My aliases
# Set up auto extension stuff
alias -s html=$BROWSER
alias -s org=$BROWSER
alias -s php=$BROWSER
alias -s com=$BROWSER
alias -s net=$BROWSER
alias -s png=feh
alias -s jpg=feh
alias -s gif=feg
alias -s sxw=soffice
alias -s doc=soffice
alias -s gz=tar -xzvf
alias -s bz2=tar -xjvf
alias -s java=$EDITOR
alias -s txt=$EDITOR
alias -s PKGBUILD=$EDITOR
# Normal aliases
alias ls='ls --color=auto -F'
alias su='sudo su'
alias apt-get='sudo apt-get'
alias lsd='ls -ld *(-/DN)'
alias lsa='ls -ld .*'
alias f='find |grep'
alias c="clear"
alias dir='ls -1'
alias ..='cd ..'
alias top='htop'
alias vi='vim'
# command L equivalent to command |less
alias -g L='|most'
# command S equivalent to command &> /dev/null &
alias -g S='&> /dev/null &'
# type a directory's name to cd to it.
compctl -/ cd