Advertisement
Guest User

Lymphatik

a guest
Sep 26th, 2009
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 12.38 KB | None | 0 0
  1. #!/bin/zsh
  2. #---
  3. #- Author: "lymphatik".
  4. #- Last updated: 2009-09-20.
  5. #--
  6. #- .zshrc: Sourced when a bash instance opens.
  7. #- GREATLY inspired by gigamo's configs.
  8. #---
  9.  
  10. #------------------------------------------------------------------------- KEYS
  11. bindkey "\e[A" history-beginning-search-backward #cursor up
  12. bindkey "\e[B" history-beginning-search-forward  #cursor down
  13. bindkey "\e[7~" beginning-of-line #home
  14. bindkey "\e[8~" vi-end-of-line # end
  15. bindkey '\eOc' forward-word # ctrl cursor right
  16. bindkey '\eOd' backward-word # ctrl cursor left
  17. bindkey "^X" push-line-or-edit # push current command into a buffer, allows you to do another command then returns to previous command
  18. bindkey ' ' magic-space
  19. bindkey -v #as I do not use vi as editor
  20.  
  21. #---------------------------------------------------------------------- VARIABLES
  22. #color in man
  23. export LESS_TERMCAP_mb=$'\E[01;31m'
  24. export LESS_TERMCAP_md=$'\E[01;31m'
  25. export LESS_TERMCAP_me=$'\E[0m'
  26. export LESS_TERMCAP_se=$'\E[0m'
  27. export LESS_TERMCAP_so=$'\E[01;44;33m'
  28. export LESS_TERMCAP_ue=$'\E[0m'
  29. export LESS_TERMCAP_us=$'\E[01;32m'
  30.  
  31. export EDITOR=gvim
  32. #nice color in the shell thanks to color wrapper
  33. typeset -U PATH #to prevent redundancy in path
  34.  
  35. #desactivated as it was bugging for make
  36. #export PATH="/usr/lib/cw:$PATH"
  37. #export PATH="/bin:/usr/bin:/sbin:/usr/sbin:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:$PATH"
  38. #export NOCOLOR_PIPE=1
  39.  
  40. #------------------------------------------------------------------------- LOGON
  41. if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
  42.   startx
  43. #  logout
  44. fi
  45.  
  46.  
  47. #---------------------------------------------------------------------- ALIASSES
  48. #- Standard aliasses
  49. alias ..='cd ..'
  50. alias ...='cd ../..'
  51. alias c='clear'
  52. alias home='cd ~'
  53. #verbose everything to avoid stupid mistake
  54. alias mv='mv -v'
  55. alias rm='rm -Iv' #the -I only for recursive and if >3 files
  56. alias cp='cp -v'
  57. alias ln='ln -v'
  58. alias ls='ls -hS --group-directories-first --color=auto' #sort files by size
  59. alias la='ls -lFA'
  60. alias lfi='ls -lhA *(-.DN)' #file only
  61. alias ldi='ls -lhd *(-/DN)' #dir only
  62. alias less=$PAGER
  63. alias vi='gvim -p' #to open multiple files in tab
  64. alias grep='grep -i --color=auto'
  65. alias wget='wget --timeout 10'
  66. alias ping='ping -c 5'
  67. alias ncmpc='ncmpcpp'
  68. alias yu='yaourt -Syu --aur'
  69. alias ys='yaourt -S'
  70. alias yss='yaourt'
  71. alias yc='yaourt -C'
  72. alias ycc='yaourt -Scc'
  73. alias yqdt='yaourt -Qdt'
  74. alias yr='yaourt -Rcs'
  75. alias pacgraph='pacgraph -c'
  76. alias bootchart='curl --form format=png --form log=@/var/log/bootchart.tgz http://render.bootchart.org:8080/bootchart/render > bootchart.png'
  77. alias efind='bash /home/lymphatik/.xmonad/script/efind'
  78. alias backup='bash /home/lymphatik/.xmonad/script/backup'
  79. alias pacman-cage='bash /home/lymphatik/.xmonad/script/pacman-cage'
  80. alias pacman-uncage='bash /home/lymphatik/.xmonad/script/pacman-uncage'
  81.  
  82. #- Global aliasses
  83. alias -g L='less'
  84. alias -g M='more'
  85. alias -g H='head'
  86. alias -g T='tail'
  87.  
  88. #- Auto open certain files
  89. alias -s {mpg,mpeg,avi,ogm,wmv,m4v,mp4,mov}='mplayer'
  90. alias -s {mp3,ogg,wav,flac}='mplayer'
  91. alias -s {html,php,com,net,org,gov,be}='firefox'
  92. alias -s txt='gvim'
  93. alias -s pdf='apvlv'
  94.  
  95. # ls settings
  96. 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';
  97.  
  98. #--------------------------------------------------------------------- FUNCTIONS
  99. calc() { echo "$*" | bc; }
  100.  
  101. #- Search by paragraph
  102. grepp() {
  103.     if test -z "$1" || test -z "$2" ; then
  104.         echo "USAGE: grepp searchterm filetosearch";
  105.     else
  106.         perl -00ne "print if /$1/i" < $2
  107.     fi
  108. }
  109. #- Commit conf files easily
  110. commit() {
  111.     git commit -a -m "$*"
  112.     git push origin master
  113. }
  114. #- Extract archive.
  115. extract() {
  116.     if [ -f "$1" ] ; then
  117.         case "$1" in
  118.             *.tar.bz2) tar xvjf "$1" ;;
  119.             *.tar.gz) tar xzvf "$1" ;;
  120.             *.tar.Z) tar xzvf "$1" ;;
  121.             *.bz2) bunzip2 "$1" ;;
  122.             *.rar) unrar x "$1" ;;
  123.             *.gz) gunzip "$1" ;;
  124.             *.jar) unzip "$1" ;;
  125.             *.tar) tar xvf "$1" ;;
  126.             *.tbz2) tar xvjf "$1" ;;
  127.             *.tgz) tar xvzf "$1" ;;
  128.             *.zip) unzip "$1" ;;
  129.             *.Z) uncompress "$1" ;;
  130.             *.7z) 7z x "$1" ;;
  131.             *) echo "'$1' Error. Please go away" ;;
  132.         esac
  133.     else
  134.         echo "'$1' is not a file"
  135.     fi
  136. }
  137.  
  138. # manage services
  139. service() {
  140.   if [ $# -lt 2 ]; then
  141.     echo "usage: service [service] [stop|start|restart]"
  142.   else
  143.     sudo /etc/rc.d/$1 $2
  144.   fi
  145. }
  146.  
  147. #- Reload .zshrc.
  148. src() {
  149.     autoload -U zrecompile
  150.     [[ -f ~/.zshrc ]] && zrecompile -p ~/.zshrc
  151.     [[ -f ~/.zcompdump ]] && zrecompile -p ~/.zcompdump
  152.     [[ -f ~/.zcompdump ]] && zrecompile -p ~/.zcompdump
  153.     [[ -f ~/.zshrc.zwc.old ]] && rm -f ~/.zshrc.zwc.old
  154.     [[ -f ~/.zcompdump.zwc.old ]] && rm -f ~/.zcompdump.zwc.old
  155.     source ~/.zshrc
  156. }
  157.  
  158. #- Create archive.
  159. roll() {
  160.     if [ -n "$1" ] ; then
  161.         FILE=$1
  162.         case $FILE in
  163.             *.tar.bz2) shift && tar cjf $FILE $* ;;
  164.             *.tar.gz) shift && tar czf $FILE $* ;;
  165.             *.tgz) shift && tar czf $FILE $* ;;
  166.             *.zip) shift && zip $FILE $* ;;
  167.             *.rar) shift && rar $FILE $* ;;
  168.         esac
  169.     else
  170.         echo "You must specify a filename."
  171.     fi
  172. }
  173.  
  174. #- Define a word - USAGE: define dog
  175. define() {
  176.     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
  177.     if [[ -s  /tmp/templookup.txt ]] ;then
  178.         until ! read response
  179.         do
  180.             echo "${response}"
  181.         done < /tmp/templookup.txt
  182.     else
  183.         echo "Sorry, I can't find the term \"${1} \""
  184.     fi
  185.     rm -f /tmp/templookup.txt > /dev/null
  186. }
  187.  
  188. #- Determine a directory sizes
  189. dirsize() {
  190.     du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
  191.     egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
  192.     egrep '^ *[0-9.]*M' /tmp/list
  193.     egrep '^ *[0-9.]*G' /tmp/list
  194.     rm -rf /tmp/list &> /dev/null
  195. }
  196.  
  197. #- Swap two filenames around
  198. swap() {
  199.     if [ $# -ne 2 ]; then
  200.         echo "Swap: 2 arguments needed"; return 1
  201.     fi
  202.     if [ ! -e $1 ]; then
  203.         echo "Swap: $1 does not exist"; return 1
  204.     fi
  205.     if [ ! -e $2 ]; then
  206.         echo "Swap: $2 does not exist"; return 1
  207.     fi
  208.     local TMPFILE=tmp.$$ ; mv $1 $TMPFILE ; mv $2 $1 ; mv $TMPFILE $2
  209. }
  210.  
  211. #------------------------------------------------------------------------ PROMPT
  212.  
  213. #change the title of urxvt based on the cmd
  214. case $TERM in
  215.     *xterm*|rxvt|rxvt-unicode|rxvt-256color|(dt|k|E)term)
  216.         precmd () { print -Pn "\e]0;$TERM - [%n@%M]%# [%~]\a" }
  217.         preexec () { print -Pn "\e]0;$TERM - [%n@%M]%# [%~] ($1)\a" }
  218.     ;;
  219.     screen)
  220.         precmd () {
  221.             print -Pn "\e]83;title \"$1\"\a"
  222.             print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~]\a"
  223.         }
  224.         preexec () {
  225.             print -Pn "\e]83;title \"$1\"\a"
  226.             print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~] ($1)\a"
  227.         }
  228.     ;;
  229. esac
  230.  
  231. #set prompt colors based on the users and chroot
  232. setprompt () {
  233.     autoload -U colors zsh/terminfo
  234.     colors
  235.     setopt prompt_subst
  236.  
  237.     for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
  238.         eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
  239.         eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
  240.     done
  241.     PR_NO_COLOR="%{$terminfo[sgr0]%}"
  242.     PR_USER="%n"
  243.     PR_DATE="%T"
  244.     PR_DIR="%~"
  245.  
  246.     UC=$PR_CYAN             #- User's color
  247.     [ $UID -eq "0" ] && UC=$PR_RED  #- Root's color
  248.  
  249.     if [ -e /chroot32 ]; then
  250.         CHROOT=" ${PR_RED}(chroot32)${PR_NO_COLOR}"
  251.     fi
  252.  
  253.     PROMPT="${UC}${PR_USER}$CHROOT ${PR_BLUE}${PR_DIR} ${UC}»${PR_NO_COLOR} "
  254.     RPROMPT="${UC}${PR_NO_COLOR} ${PR_DATE}"
  255.     PS2=" ${UC}»${PR_NO_COLOR} "
  256. }
  257.  
  258. setprompt
  259.  
  260.  
  261. #------------------------------------------------------------- COMPLETION SYSTEM
  262. #- Expansion options.
  263. zstyle ':completion:*' completer _expand _complete _prefix _correct _approximate
  264. zstyle ':completion::prefix-1:*' completer _complete
  265. zstyle ':completion:incremental:*' completer _complete _correct
  266. zstyle ':completion:predict:*' completer _complete
  267.  
  268. #- Completion caching.
  269. zstyle ':completion::complete:*' use-cache 1
  270. zstyle ':completion::complete:*' cache-path ~/.cache/zsh
  271.  
  272. #- Expand partial paths.
  273. zstyle ':completion:*' expand 'yes'
  274. zstyle ':completion:*' squeeze-slashes 'yes'
  275.  
  276. zstyle ':completion:*' use-cache on
  277. zstyle ':completion:*' cache-path ~/.zsh/cache
  278.  
  279. #- Include non-hidden directories in globbed file completions
  280. #- for certain commands.
  281. zstyle ':completion::complete:*' '\'
  282.  
  283. #- Tag-order 'globbed-files directories' all-files.
  284. zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)'
  285.  
  286. #- Don't complete backup files as executables.
  287. zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'
  288. zstyle ':completion:*:-command-:*:'    verbose false
  289.  
  290. #- Separate matches into groups.
  291. zstyle ':completion:*:matches' group 'yes'
  292.  
  293. #- Describe each match group.
  294. zstyle ':completion:*:descriptions' format "%B---- %d%b"
  295.  
  296. #- Messages/warnings format.
  297. zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
  298. zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b'
  299.  
  300. #- Describe options in full.
  301. zstyle ':completion:*:options' description 'yes'
  302. zstyle ':completion:*:options' auto-description '%d'
  303.  
  304. #- Complete manual by their section.
  305. zstyle ':completion:*:manuals'    separate-sections true
  306. zstyle ':completion:*:manuals.*'  insert-sections   true
  307.  
  308. zstyle ':completion:*' format '%d:'
  309. zstyle ':completion:*' group-name ''
  310. zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
  311. zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*'
  312. zstyle ':completion:*' max-errors 3
  313. zstyle ':completion:*' menu select=3 yes
  314. zstyle ':completion:*' prompt 'Alternatives %e:'
  315. zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
  316. zstyle :compinstall filename "$HOME/.zshrc"
  317.  
  318.  
  319. #----------------------------------------------------------------------- OPTIONS
  320. #- History.
  321. setopt INC_APPEND_HISTORY EXTENDED_HISTORY HIST_IGNORE_DUPS HIST_FIND_NO_DUPS
  322. setopt EXTENDED_HISTORY HIST_EXPIRE_DUPS_FIRST
  323. setopt HIST_REDUCE_BLANKS HIST_SAVE_NO_DUPS
  324. HISTSIZE=10000
  325. SAVEHIST=10000
  326. HISTFILE=~/.zshhistory
  327.  
  328. #- Load modules.
  329. autoload -U compinit
  330. compinit 2>/dev/null
  331. autoload zmv        # For renaming.
  332. autoload -U zcalc   # For math.
  333. compctl -/ cd       # Type a dir's name to cd into it.
  334.  
  335. #- Other options.
  336. setopt autopushd pushdminus pushdsilent pushdtohome
  337. setopt autocd            # automatically cd to paths
  338. setopt cdablevars
  339. setopt globdots
  340. setopt ignoreeof
  341. setopt interactivecomments
  342. setopt banghist
  343. #setopt noclobber
  344. setopt hist_reduce_blanks
  345. setopt hist_ignore_space
  346. setopt SH_WORD_SPLIT
  347. setopt nohup
  348. setopt nobeep
  349. setopt automenu
  350. setopt autopushd            # Automatically append dirs to the push/pop list
  351. setopt pushdignoredups      # And don't duplicate them
  352. setopt cdablevars           # Avoid the need for an explicit $
  353. setopt nolisttypes          # Show types in completion
  354. setopt extendedglob         # Weird & wacky pattern matching - yay zsh!
  355. setopt completeinword       # Not just at the end
  356. setopt alwaystoend          # When complete from middle, move cursor
  357. setopt nopromptcr           # Don't add \n which overwrites cmds with no \n
  358. setopt histverify           # When using ! cmds, confirm first
  359. setopt interactivecomments  # Escape commands so I can use them later
  360. setopt hist_ignore_dups     # when I run a command several times, only store one
  361. setopt printexitvalue          # alert me if something's failed
  362.  
  363.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement