Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/zsh
- #---
- #- Author: "lymphatik".
- #- Last updated: 2009-09-20.
- #--
- #- .zshrc: Sourced when a bash instance opens.
- #- GREATLY inspired by gigamo's configs.
- #---
- #------------------------------------------------------------------------- KEYS
- bindkey "\e[A" history-beginning-search-backward #cursor up
- bindkey "\e[B" history-beginning-search-forward #cursor down
- bindkey "\e[7~" beginning-of-line #home
- bindkey "\e[8~" vi-end-of-line # end
- bindkey '\eOc' forward-word # ctrl cursor right
- bindkey '\eOd' backward-word # ctrl cursor left
- bindkey "^X" push-line-or-edit # push current command into a buffer, allows you to do another command then returns to previous command
- bindkey ' ' magic-space
- bindkey -v #as I do not use vi as editor
- #---------------------------------------------------------------------- VARIABLES
- #color in man
- export LESS_TERMCAP_mb=$'\E[01;31m'
- export LESS_TERMCAP_md=$'\E[01;31m'
- export LESS_TERMCAP_me=$'\E[0m'
- export LESS_TERMCAP_se=$'\E[0m'
- export LESS_TERMCAP_so=$'\E[01;44;33m'
- export LESS_TERMCAP_ue=$'\E[0m'
- export LESS_TERMCAP_us=$'\E[01;32m'
- export EDITOR=gvim
- #nice color in the shell thanks to color wrapper
- typeset -U PATH #to prevent redundancy in path
- #desactivated as it was bugging for make
- #export PATH="/usr/lib/cw:$PATH"
- #export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:$PATH"
- #export NOCOLOR_PIPE=1
- #------------------------------------------------------------------------- LOGON
- if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
- startx
- # logout
- fi
- #---------------------------------------------------------------------- ALIASSES
- #- Standard aliasses
- alias ..='cd ..'
- alias ...='cd ../..'
- alias c='clear'
- alias home='cd ~'
- #verbose everything to avoid stupid mistake
- alias mv='mv -v'
- alias rm='rm -Iv' #the -I only for recursive and if >3 files
- alias cp='cp -v'
- alias ln='ln -v'
- alias ls='ls -hS --group-directories-first --color=auto' #sort files by size
- alias la='ls -lFA'
- alias lfi='ls -lhA *(-.DN)' #file only
- alias ldi='ls -lhd *(-/DN)' #dir only
- alias less=$PAGER
- alias vi='gvim -p' #to open multiple files in tab
- alias grep='grep -i --color=auto'
- alias wget='wget --timeout 10'
- alias ping='ping -c 5'
- alias ncmpc='ncmpcpp'
- alias yu='yaourt -Syu --aur'
- alias ys='yaourt -S'
- alias yss='yaourt'
- alias yc='yaourt -C'
- alias ycc='yaourt -Scc'
- alias yqdt='yaourt -Qdt'
- alias yr='yaourt -Rcs'
- alias pacgraph='pacgraph -c'
- alias bootchart='curl --form format=png --form log=@/var/log/bootchart.tgz http://render.bootchart.org:8080/bootchart/render > bootchart.png'
- alias efind='bash /home/lymphatik/.xmonad/script/efind'
- alias backup='bash /home/lymphatik/.xmonad/script/backup'
- alias pacman-cage='bash /home/lymphatik/.xmonad/script/pacman-cage'
- alias pacman-uncage='bash /home/lymphatik/.xmonad/script/pacman-uncage'
- #- Global aliasses
- alias -g L='less'
- alias -g M='more'
- alias -g H='head'
- alias -g T='tail'
- #- Auto open certain files
- alias -s {mpg,mpeg,avi,ogm,wmv,m4v,mp4,mov}='mplayer'
- alias -s {mp3,ogg,wav,flac}='mplayer'
- alias -s {html,php,com,net,org,gov,be}='firefox'
- alias -s txt='gvim'
- alias -s pdf='apvlv'
- # ls settings
- export LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=01;33:so=01;35:do=01;35:bd=00;33;01:cd=00;33;01:or=05;31;01:ex=01;37:*.tar=00;32:*.tgz=00;32:*.arj=00;32:*.taz=00;32:*.lzh=00;32:*.zip=00;32:*.z=01;32:*.Z=01;32:*.gz=01;32:*.bz2=01;32:*.jar=01;32:*.rar=01;32:*.ace=01;32:*.7z=01;32:*.jpg=00;36:*.jpeg=00;36:*.gif=00;36:*.bmp=00;36:*.pbm=00;36:*.pgm=00;36:*.ppm=00;36:*.tga=00;36:*.xbm=00;36:*.xpm=00;36:*.tif=00;36:*.tiff=00;36:*.png=00;36:*.svg=00;36:*.svgz=00;36:*.mng=00;36:*.pcx=00;36:*.nuv=00;36:*.flc=00;36:*.fli=00;36:*.flv=00;36:*.gl=00;36:*.dl=00;36:*.xcf=00;36:*.xwd=00;36:*.yuv=00;36:*.aac=00;33:*.au=00;33:*.flac=00;33:*.mid=00;33:*.midi=00;33:*.mka=00;33:*.mp3=00;33:*.mpc=00;33:*.ogg=00;33:*.ra=00;33:*.wav=00;33:*.mov=01;36:*.mpg=01;36:*.mpeg=01;36:*.m2v=01;36:*.mkv=01;36:*.ogm=01;36:*.mp4=01;36:*.m4v=01;36:*.mp4v=01;36:*.vob=01;36:*.qt=01;36:*.wmv=01;36:*.asf=01;36:*.rm=01;36:*.rmvb=01;36:*.avi=01;36';
- #--------------------------------------------------------------------- FUNCTIONS
- calc() { echo "$*" | bc; }
- #- Search by paragraph
- grepp() {
- if test -z "$1" || test -z "$2" ; then
- echo "USAGE: grepp searchterm filetosearch";
- else
- perl -00ne "print if /$1/i" < $2
- fi
- }
- #- Commit conf files easily
- commit() {
- git commit -a -m "$*"
- git push origin master
- }
- #- Extract archive.
- extract() {
- if [ -f "$1" ] ; then
- case "$1" in
- *.tar.bz2) tar xvjf "$1" ;;
- *.tar.gz) tar xzvf "$1" ;;
- *.tar.Z) tar xzvf "$1" ;;
- *.bz2) bunzip2 "$1" ;;
- *.rar) unrar x "$1" ;;
- *.gz) gunzip "$1" ;;
- *.jar) unzip "$1" ;;
- *.tar) tar xvf "$1" ;;
- *.tbz2) tar xvjf "$1" ;;
- *.tgz) tar xvzf "$1" ;;
- *.zip) unzip "$1" ;;
- *.Z) uncompress "$1" ;;
- *.7z) 7z x "$1" ;;
- *) echo "'$1' Error. Please go away" ;;
- esac
- else
- echo "'$1' is not a file"
- fi
- }
- # manage services
- service() {
- if [ $# -lt 2 ]; then
- echo "usage: service [service] [stop|start|restart]"
- else
- sudo /etc/rc.d/$1 $2
- fi
- }
- #- Reload .zshrc.
- src() {
- autoload -U zrecompile
- [[ -f ~/.zshrc ]] && zrecompile -p ~/.zshrc
- [[ -f ~/.zcompdump ]] && zrecompile -p ~/.zcompdump
- [[ -f ~/.zcompdump ]] && zrecompile -p ~/.zcompdump
- [[ -f ~/.zshrc.zwc.old ]] && rm -f ~/.zshrc.zwc.old
- [[ -f ~/.zcompdump.zwc.old ]] && rm -f ~/.zcompdump.zwc.old
- source ~/.zshrc
- }
- #- Create archive.
- roll() {
- if [ -n "$1" ] ; then
- FILE=$1
- case $FILE in
- *.tar.bz2) shift && tar cjf $FILE $* ;;
- *.tar.gz) shift && tar czf $FILE $* ;;
- *.tgz) shift && tar czf $FILE $* ;;
- *.zip) shift && zip $FILE $* ;;
- *.rar) shift && rar $FILE $* ;;
- esac
- else
- echo "You must specify a filename."
- fi
- }
- #- Define a word - USAGE: define dog
- define() {
- lynx -dump "http://www.google.com/search?hl=en&q=define%3A+${1}&btnG=Google+Search" | grep -m 3 -w "*" | sed 's/;/ -/g' | cut -d- -f1 > /tmp/templookup.txt
- if [[ -s /tmp/templookup.txt ]] ;then
- until ! read response
- do
- echo "${response}"
- done < /tmp/templookup.txt
- else
- echo "Sorry, I can't find the term \"${1} \""
- fi
- rm -f /tmp/templookup.txt > /dev/null
- }
- #- Determine a directory sizes
- dirsize() {
- du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
- egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
- egrep '^ *[0-9.]*M' /tmp/list
- egrep '^ *[0-9.]*G' /tmp/list
- rm -rf /tmp/list &> /dev/null
- }
- #- Swap two filenames around
- swap() {
- if [ $# -ne 2 ]; then
- echo "Swap: 2 arguments needed"; return 1
- fi
- if [ ! -e $1 ]; then
- echo "Swap: $1 does not exist"; return 1
- fi
- if [ ! -e $2 ]; then
- echo "Swap: $2 does not exist"; return 1
- fi
- local TMPFILE=tmp.$$ ; mv $1 $TMPFILE ; mv $2 $1 ; mv $TMPFILE $2
- }
- #------------------------------------------------------------------------ PROMPT
- #change the title of urxvt based on the cmd
- case $TERM in
- *xterm*|rxvt|rxvt-unicode|rxvt-256color|(dt|k|E)term)
- precmd () { print -Pn "\e]0;$TERM - [%n@%M]%# [%~]\a" }
- preexec () { print -Pn "\e]0;$TERM - [%n@%M]%# [%~] ($1)\a" }
- ;;
- screen)
- precmd () {
- print -Pn "\e]83;title \"$1\"\a"
- print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~]\a"
- }
- preexec () {
- print -Pn "\e]83;title \"$1\"\a"
- print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~] ($1)\a"
- }
- ;;
- esac
- #set prompt colors based on the users and chroot
- setprompt () {
- autoload -U colors zsh/terminfo
- colors
- setopt prompt_subst
- for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
- eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
- eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
- done
- PR_NO_COLOR="%{$terminfo[sgr0]%}"
- PR_USER="%n"
- PR_DATE="%T"
- PR_DIR="%~"
- UC=$PR_CYAN #- User's color
- [ $UID -eq "0" ] && UC=$PR_RED #- Root's color
- if [ -e /chroot32 ]; then
- CHROOT=" ${PR_RED}(chroot32)${PR_NO_COLOR}"
- fi
- PROMPT="${UC}${PR_USER}$CHROOT ${PR_BLUE}${PR_DIR} ${UC}»${PR_NO_COLOR} "
- RPROMPT="${UC}${PR_NO_COLOR} ${PR_DATE}"
- PS2=" ${UC}»${PR_NO_COLOR} "
- }
- setprompt
- #------------------------------------------------------------- COMPLETION SYSTEM
- #- Expansion options.
- zstyle ':completion:*' completer _expand _complete _prefix _correct _approximate
- zstyle ':completion::prefix-1:*' completer _complete
- zstyle ':completion:incremental:*' completer _complete _correct
- zstyle ':completion:predict:*' completer _complete
- #- Completion caching.
- zstyle ':completion::complete:*' use-cache 1
- zstyle ':completion::complete:*' cache-path ~/.cache/zsh
- #- Expand partial paths.
- zstyle ':completion:*' expand 'yes'
- zstyle ':completion:*' squeeze-slashes 'yes'
- zstyle ':completion:*' use-cache on
- zstyle ':completion:*' cache-path ~/.zsh/cache
- #- Include non-hidden directories in globbed file completions
- #- for certain commands.
- zstyle ':completion::complete:*' '\'
- #- Tag-order 'globbed-files directories' all-files.
- zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)'
- #- Don't complete backup files as executables.
- zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
- zstyle ':completion:*:-command-:*:' verbose false
- #- Separate matches into groups.
- zstyle ':completion:*:matches' group 'yes'
- #- Describe each match group.
- zstyle ':completion:*:descriptions' format "%B---- %d%b"
- #- Messages/warnings format.
- zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
- zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b'
- #- Describe options in full.
- zstyle ':completion:*:options' description 'yes'
- zstyle ':completion:*:options' auto-description '%d'
- #- Complete manual by their section.
- zstyle ':completion:*:manuals' separate-sections true
- zstyle ':completion:*:manuals.*' insert-sections true
- zstyle ':completion:*' format '%d:'
- zstyle ':completion:*' group-name ''
- zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
- zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*'
- zstyle ':completion:*' max-errors 3
- zstyle ':completion:*' menu select=3 yes
- zstyle ':completion:*' prompt 'Alternatives %e:'
- zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
- zstyle :compinstall filename "$HOME/.zshrc"
- #----------------------------------------------------------------------- OPTIONS
- #- History.
- setopt INC_APPEND_HISTORY EXTENDED_HISTORY HIST_IGNORE_DUPS HIST_FIND_NO_DUPS
- setopt EXTENDED_HISTORY HIST_EXPIRE_DUPS_FIRST
- setopt HIST_REDUCE_BLANKS HIST_SAVE_NO_DUPS
- HISTSIZE=10000
- SAVEHIST=10000
- HISTFILE=~/.zshhistory
- #- Load modules.
- autoload -U compinit
- compinit 2>/dev/null
- autoload zmv # For renaming.
- autoload -U zcalc # For math.
- compctl -/ cd # Type a dir's name to cd into it.
- #- Other options.
- setopt autopushd pushdminus pushdsilent pushdtohome
- setopt autocd # automatically cd to paths
- setopt cdablevars
- setopt globdots
- setopt ignoreeof
- setopt interactivecomments
- setopt banghist
- #setopt noclobber
- setopt hist_reduce_blanks
- setopt hist_ignore_space
- setopt SH_WORD_SPLIT
- setopt nohup
- setopt nobeep
- setopt automenu
- setopt autopushd # Automatically append dirs to the push/pop list
- setopt pushdignoredups # And don't duplicate them
- setopt cdablevars # Avoid the need for an explicit $
- setopt nolisttypes # Show types in completion
- setopt extendedglob # Weird & wacky pattern matching - yay zsh!
- setopt completeinword # Not just at the end
- setopt alwaystoend # When complete from middle, move cursor
- setopt nopromptcr # Don't add \n which overwrites cmds with no \n
- setopt histverify # When using ! cmds, confirm first
- setopt interactivecomments # Escape commands so I can use them later
- setopt hist_ignore_dups # when I run a command several times, only store one
- setopt printexitvalue # alert me if something's failed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement