davidkra /.zshrc

#########################################
# .zshrc
# The Z Shell config file
# Based on coders .zshrc
#########################################
# {{{ History 
##################################################################
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000

setopt appendhistory
setopt sharehistory  # share history between multiple running terminals
# }}}

# {{{ Key bindings 
#############################################################
# REMINDER: C-V key  -  will print out key, for a nice reference
bindkey -e                                   # vim sucks

# Useful piping shortcuts
bindkey -s '^|l' "|less\n"                   # c-| l  pipe to less
bindkey -s '^|g' '|grep ""^[OD'             # c-| g  pipe to grep
bindkey -s '^|a' "|awk '{print $}'^[OD^[OD"  # c-| a  pipe to awk
bindkey -s '^|s' '|sed -e "s///g"^[OD^[OD^[OD^[OD' # c-| s  pipe to sed

# Input controls
bindkey '^[[1;3D' backward-word    # alt + LEFT
bindkey '^[[1;3C' forward-word     # alt + RIGHT
bindkey '_^?' backward-delete-word # alt + BACKSPACE  delete word backward
bindkey '^[[3;3~' delete-word      # alt + DELETE  delete word forward
bindkey '^[' self-insert           # alt + ENTER  allow multiline input
bindkey '_t' transpose-words
# }}}

# {{{ Completion 
###############################################################
## Generated by compinstall
zstyle :compinstall filename '/home/davidk/.zshrc'
autoload -Uz compinit
compinit
## End Generated by compinstall

## Taken from mako's .zshrc
zstyle ':completion:*' menu select=1 _complete _ignored _approximate
# allow one error for every three characters typed in approximate completer
zstyle -e ':completion:*:approximate:*' max-errors \
    'reply=( $(( ($#PREFIX+$#SUFFIX)/2 )) numeric )'
# list of completers to use
zstyle ':completion:*::::' completer _expand _complete _ignored 
_approximate
# seperate close errors from matches
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
## End taken from mako's .zshrc
# }}}

## {{{ Aliases 
#################################################################
alias grep="egrep --color=auto"  # color grep output
alias ls="ls --color"            # always show color
alias l="ls -lh --color"         # laziness strikes again.
alias la="ls -alh --color"       # list, show all, in a humane way
alias ..="cd .."                 # save 3 keystrokes...
alias cd..="cd .."               # for annoying typos...
alias emacs="emacs -nw"          # always run emacs inside the console
alias rm="rm -i"                 # can never be too careful...
alias diff=colordiff             # pretty colors...
alias p=pwd                      # more lazyness...
alias c="clear;fortune -a"          # another quickie
alias sr="screen -R"             # attach to screen session if running
alias du="du -h"                 # humane treatment
alias df="df -h"                 # humane treatment again
alias ut="tar xfv"               # yay, less random letters to know...
alias su="su -s /bin/zsh"        # make it use zsh
alias a="g '^alias' < ~/.zshrc"  # QUICKKEY - alias list
alias d=dcop                     # QUICKKEY - dcop connections
alias h="htop -u $(whoami) -t"   # QUICKKEY - system monitor
alias j=jobs                     # QUICKKEY - show jobs
alias k=kill                     # QUICKKEY - kill process
alias e=$EDITOR                  # QUICKKEY - edit quickly
alias m=more                     # QUICKKEY - yeah
alias q=exit                     # QUICKKEY - like vim
alias nano='nano -w'
# }}}

# {{{ Functions 
################################################################
# visit bash quickly
function bashorg() { lynx -dump "www.bash.org?$1" | less; }

# grabs latest .zshrc from dotfiles.org, and moves .zshrc to .zshrc.old
# backs up .zshrc.old to .zshrc.old.old just in case ;)
function updatezshrc() {
        echo "Starting in 5 seconds... Ctrl+C to abort..."
        sleep 5

        # back up .zshrc.old just in case, only if it exists
        if [[ $(file .zshrc.old) != "" ]]; then
                mv .zshrc.old .zshrc.old.old
        fi

        # Back up .zshrc
        mv .zshrc .zshrc.old
        
        # Get new .zshrc from dotfiles.org
        curl -o .zshrc http://dotfiles.org/~coder_/.zshrc
}
# }}}

# {{{ Pre-functions 
############################################################
# Set title of window
function preexec() {
  # When I print to the xterm title, \b doesn't seem to work, so this
  # will hackily solve the problem of putting $FOOx$BAR, very ugly yes
  # and there is probably a better way to do this in zsh, but I'm new to it
  # also, why am I writing a comment like this to myself?
  export size="$(echo \"$COLUMNS@x$LINES\" | sed s/@//g | sed s/\"//g)"

  # Show screen window, or running command
  if [[ "$WINDOW" == "" ]]; then
    if [[ $1 != "" ]]; then
      # show running command, because it doesn't stick like screen
      print -Pn "\e]0;$1 - $size\a"
    else
      print -Pn "\e]0;zsh - $size\a"
    fi
  fi
}

# Show the directory in terminal title
case $TERM in
  xterm*)
        precmd() { preexec }
    ;;
esac
# }}}

# {{{ Variables 
################################################################
export BROWSER=/opt/firefox/firefox   # blah, duh.... etc.
export VISUAL='nano'                  # blah
export EDITOR=$VISUAL                 # mi editero
export SVN_EDITOR=$VISUAL             # subversion editor
export ZLS_COLORS=$LS_COLORS          # show ls colors.. grr..
# }}}

# {{{ Prompt 
###################################################################
# Different prompts depending on if screen is running 
source $HOME/.zsh/zshterm
# }}}

# {{{ Misc. Options 
############################################################
setopt autocd
setopt cdablevars
setopt correct  # correct commands
# }}}

# {{{ Startup output 
###########################################################
fortune -a
# }}}