shosei

Bash init file

Feb 23rd, 2012
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.46 KB | None | 0 0
  1. #Filesystem
  2. alias noproxy="http_proxy= HTTP_PROXY= https_proxy= HTTPS_PROXY= ftp_proxy= FTP_PROXY="
  3. alias rs="nice rsync --archive --no-owner --sparse --hard-links --partial --progress"
  4. alias rsz="rs --compress-level=9 --skip-compress=gz/zip/z/rpm/deb/iso/bz2/t[gb]z/7z/mp[34]/mov/avi/ogg/jpg/jpeg/rar/gif/png/dat"
  5. alias port="sudo nice port"
  6. alias mvn="nice mvn"
  7. alias cp="nice cp -v"
  8. alias mv="nice mv -v"
  9. alias tree="tree -F --dirsfirst"
  10. if ls --color >/dev/null 2>/dev/null; then
  11.     alias ls="ls -bFk --color=auto"
  12. else
  13.     alias ls="ls -bFkG"
  14. fi
  15. alias ll="ls -lh"
  16. alias l=" ll -a"
  17. alias df="nice df -h"
  18.  
  19.  
  20.  
  21. # Aliases
  22. alias cal="cal -m -3"
  23. alias git="nice git"
  24. alias gsh="git stash"
  25. alias gst="git status --short --branch"
  26. alias gsu="git submodule update --recursive --merge"
  27. alias gdf="git diff"
  28. alias gdt="git difftool"
  29. alias glo="git log"
  30. alias gps="git push"
  31. alias gpl="git pull"
  32. alias gco="git checkout"
  33. alias gci="git commit"
  34. alias gad="git add"
  35. alias grm="git rm"
  36. alias gmv="git mv"
  37. alias gtg="git tag"
  38. alias gbr="git branch"
  39. alias gs="git svn"
  40.  
  41. alias n="netstat -np tcp"
  42. alias mtr="mtr -t"
  43. alias nmap="nmap -v -v -T5"
  44. alias nmapp="nmap -P0 -A --osscan_limit"
  45. alias pktstat="sudo pktstat -tBFT"
  46.  
  47. # Shell History
  48. shopt -s histappend
  49. HISTCONTROL=ignoreboth
  50. HISTSIZE=
  51. HISTFILE=~/.bash.log
  52. HISTFILESIZE=
  53. HISTTIMEFORMAT='%F %T%t'
  54.  
  55. # Prompt
  56. PS1='\h\[$blue\] $(git-repo-status)\W \[$red\]${?/#0/\[$green\]}\$\[$reset\] '
  57. if (( EUID )); then
  58.     PS1='\[$reset$bold$green\]\u@'$PS1
  59. else
  60.     PS1='\[$reset$bold$red\]'$PS1
  61. fi
  62. forcePS1ToFront() {
  63.     origExitCode=$?
  64.     read r c < <(cloc)
  65.     (( c > 1 )) && printf '\n' >&2
  66.     return $origExitCode
  67. }
  68. #PS1='$(forcePS1ToFront)'$PS1 # Put the prompt on a new line if the cursor isn't in the beginning of the line.
  69. #PS1='\[$reset$bold$green\]\u@\h\[$blue\] \W \[$green\]$(: "${?#0}"; printf "\[%s\]" "${_:+$save$red\r$_ $load}")\$\[$reset\] '
  70.  
  71. # Colors
  72. if      [[ -f /etc/DIR_COLORS.env ]]
  73. then        source "/etc/DIR_COLORS.env"
  74. elif    [[ -f /etc/DIR_COLORS ]] && exists dircolors
  75. then        eval "$(dircolors -b "/etc/DIR_COLORS")"
  76. fi
  77. if      [[ -f ~/.dir_colors.env ]]
  78. then        source ~/.dir_colors.env
  79. elif    [[ -f ~/.dir_colors ]] && exists dircolors
  80. then        eval "$(dircolors -b ~/.dir_colors)"
  81. fi
  82.  
  83. # functions
  84. i() {
  85.     bash --rcfile <(printf '%s\n' "$(<~/.bashrc)" "HISTFILE='$HISTFILE.i'" "PS1='\[$yellow\]~\[$reset\]$PS1'" "cd; clear"); clear
  86. }
  87. d() {
  88.     if exists colordiff; then
  89.         colordiff -ur "$@"
  90.     elif exists diff; then
  91.         diff -ur "$@"
  92.     elif exists comm; then
  93.  
  94. # functions - filesystem
  95.         comm -3 "$1" "$2"
  96.     fi | less
  97. }
  98. # f pattern [find-args]
  99. f() {
  100.     local root pattern=$1; shift
  101.  
  102.     find "${@:-.}" -iname "*$pattern*"
  103. }
  104. rerun() {
  105.     local h history histories dialogMenu=() startIndex
  106.    
  107.     # Load in history entries (ignoring the last)
  108.     IFS=$'\n' read -r -d '' -a histories < <(history | tail -n "${1:-10}")
  109.     unset histories[${#histories[@]}-1]
  110.  
  111.     # Build a dialog(1) menu and show it to ask for the starting index.
  112.     for h in "${!histories[@]}"; do dialogMenu+=( "$h" "${histories[h]}" ); done
  113.     startIndex=$(dialog --stdout --menu "Bash History" 0 0 0 "${dialogMenu[@]}")
  114.  
  115.     # Run all history commands starting from the starting index.
  116.     for history in "${histories[@]:startIndex}"; do
  117.         eval "${history#*$'\t'}" || break
  118.     done
  119. }
  120. sw() {
  121.     local bak="$1~"
  122.     while [[ -e $bak ]]
  123.     do bak+='~'; done
  124.     mv -v "$1" "$bak"
  125.     mv -v "$2" "$1"
  126.     mv -v "$bak" "$2"
  127. }
  128. ppg() {
  129.     pat=$1; shift
  130.     p | grep -i "$@" "$pat"
  131. }
  132. cwatch() {
  133.     while sleep .5; do
  134.         o="$("$@")"
  135.         clear && echo "$o"
  136.     done
  137. }
  138. mvns() {
  139.     export PATH=/usr/local/share/soylatte16-amd64-1.0.3/bin:${PATH}
  140.     export JAVA_HOME=/usr/local/share/soylatte16-amd64-1.0.3
  141.  
  142.     mvn "$@"
  143. }
  144. mvnroot() {
  145.     local p=$PWD c=${1:-1}
  146.     until p=${p%/*}; [[ -e "$p/pom.xml" ]] && (( --c <= 0 )); do :; done
  147.  
  148.     echo "${p}${red}${PWD#$p}${reset}"
  149.     cd "$p"
  150. }
  151. gf() {
  152.     git-forest -a --sha "${@:---all}" | less
  153. }
  154. gd() {
  155.     git describe --always --dirty
  156. }
  157. gdm() {
  158.     emit "GIT Daemon starting with base path: $(shorten "$PWD")"
  159.     git daemon --base-path=. "$@" &
  160. }
  161. git-redo-move() {
  162.     (( $# == 2 ))   || { emit -r "Expected two parameters; [source] [destination]."; return; }
  163.     [[ -e $2 ]]     || { emit -r "$2 doesn't exist, can't redo move."; return; }
  164.     [[ ! -e $1 ]]   || { emit -r "$1 exists, don't want to overwrite, aborting redo move."; return; }
  165.     mkdir -p "${1%/*}" && \mv "$2" "$1" && git mv "$1" "$2" && rmdir -p "${1%/*}"
  166. }
  167. git-repo-status() {
  168.     local exit=$? cwd=$PWD repo= tag
  169.  
  170.     while [[ $cwd ]]; do
  171.         [[ -d $cwd/.git ]] && { repo=git; break; }
  172.  
  173.         cwd=${cwd%/*}
  174.     done
  175.  
  176.     case $repo in
  177.         git)
  178.             if ! tag=$(git describe --tags --exact-match 2>&-); then
  179.                 tag=$(git describe --tags 2>&-)
  180.                 tag=${tag%-*} # Chop off hash.
  181.             fi
  182.             printf '[%s%s%s] \n' "${cwd##*/}" "${tag:+:}" "$tag"
  183.         ;;
  184.     esac
  185.  
  186.     return $exit
  187. }
  188. portget() {
  189.     (( $# )) || { emit -r "$0 [revision] [category/portname]"; return; }
  190.  
  191.     [[ -e "${2#*/}" ]] && { ask -Ny! 'Target exists, delete?' && rm -rf "${2#*/}" || return; }
  192.     svn co -r "$1" http://svn.macports.org/repository/macports/trunk/dports/"$2"
  193.     cd "${2#*/}"
  194. }
  195.  
  196. # Fink environment
  197. test -r /sw/bin/init.sh && . /sw/bin/init.sh
Advertisement
Add Comment
Please, Sign In to add comment