Bash Initialization Script
Bash Initialization Script
/bin/bash
# ~/.bashrc
#
# Bash Shell initialization script.
#
#-------------------------#`
# SHELL - INITIALIZATION #
#-------------------------#
[[ $PATH = *local/bin* ]] || PATH=$PATH:/usr/local/bin
[[ $- = *i* ]] || return
source bashlib
#-------------------------#
# ALIASSES - FILESYSTEM #
#-------------------------#
alias noproxy="http_proxy= HTTP_PROXY= https_proxy= HTTPS_PROXY= ftp_proxy= FTP_
PROXY="
alias rs="nice rsync --archive --no-owner --sparse --hard-links --partial --prog
ress"
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"
alias port="sudo nice port"
alias mvn="nice mvn"
alias cp="nice cp -v"
alias mv="nice mv -v"
alias tree="tree -F --dirsfirst"
if ls --color >/dev/null 2>/dev/null; then
alias ls="ls -bFk --color=auto"
else
alias ls="ls -bFkG"
fi
alias ll="ls -lh"
alias l=" ll -a"
alias df="nice df -h"
#-------------------------#
# ALIASSES - APPLICATIONS #
#-------------------------#
alias cal="cal -m -3"
alias git="nice git"
alias gsh="git stash"
alias gst="git status --short --branch"
alias gsu="git submodule update --recursive --merge"
alias gdf="git diff"
alias gdt="git difftool"
alias glo="git log"
alias gps="git push"
alias gpl="git pull"
alias gco="git checkout"
alias gci="git commit"
alias gad="git add"
alias grm="git rm"
alias gmv="git mv"
alias gtg="git tag"
alias gbr="git branch"
alias gs="git svn"
#-------------------------#
# ALIASSES - SYSTEM
#
#-------------------------#
s() {
fc -s "$1=$2"
}
exists wdiff && \
alias wdiff="wdiff -a"
exists less && \
alias more="less" || \
alias less="more"
alias kbg='bg; kill $!; fg'
exists ltrace && \
alias trace="ltrace -C -f -n 4 -S"
exists pcregrep && \
alias pcregrep="pcregrep --color=auto"
alias grep="grep -I --color=auto"
alias egrep="grep -E"
alias fgrep="grep -F"
alias pg="pgrep -l"
if exists pstree; then
p() {
if pstree -A >/dev/null 2>&1; then
pstree -Aahlpu
else
[[ -t 1 ]] \
&& pstree -w -g2 \
|| pstree -w -g1 | recode -fg IBM850..UTF8
fi
}
else
if ps auxf >/dev/null 2>&1; then
p() { ps auxf; }
else
p() { ps aux; }
fi
fi
alias pp="p | less"
top -u -h >/dev/null 2>&1 && \
alias top="top -S -u -stats pid,ppid,user,cpu,time,threads,state,rprvt,vprvt
,faults,command"
#-------------------------#
# ALIASSES - NETWORKING #
#-------------------------#
alias n="netstat -np tcp"
alias mtr="mtr -t"
alias nmap="nmap -v -v -T5"
alias nmapp="nmap -P0 -A --osscan_limit"
alias pktstat="sudo pktstat -tBFT"
#-------------------------#
# OS-SPECIFIC
#
#-------------------------#
if [[ $MACHTYPE = *darwin* ]]; then
# MAC ----------------#
qview() {
files=("$@"); i=0
while true; do
file=${files[i]}
qlmanage -p "$file" & pid=$!
read -sn1 key
kill $pid || key=q
wait $pid
case $key in
q) return ;;
p) let i-- ;;
*) let i++ ;;
esac
(( i < ${#files[@]} )) || break
(( i < 0 )) && i=0
done
} 2>/dev/null
qthumb() {
qlmanage -t "$@" & pid=$!
read -sn1
kill $pid; wait $pid
} 2>/dev/null
fi
#-----------------------------#
# SHELL - HISTORY
#
#-----------------------------#
shopt -s histappend
HISTCONTROL=ignoreboth
HISTSIZE=
HISTFILE=~/.bash.log
HISTFILESIZE=
HISTTIMEFORMAT='%F %T%t'
#-------------------------#
# SHELL - LOOK AND FEEL #
#-------------------------#
shopt -s extglob
shopt -qs globstar
shopt -qs checkwinsize
shopt -qs hostcomplete
shopt -qs no_empty_cmd_completion
stty stop undef
stty -echoctl
#[[ -f /etc/bash_completion ]] && \
#
source /etc/bash_completion
[[ -f ~/.share/git-svn-extensions/source.sh ]] && \
source ~/.share/git-svn-extensions/source.sh
# Terminal title for xterm/rxvt/screen.
case "$TERM" in
?term*|rxvt*|gnome*|interix)
-f /etc/DIR_COLORS.env ]]
source "/etc/DIR_COLORS.env"
-f /etc/DIR_COLORS ]] && exists dircolors
eval "$(dircolors -b "/etc/DIR_COLORS")"
-f ~/.dir_colors.env ]]
source ~/.dir_colors.env
-f ~/.dir_colors ]] && exists dircolors
eval "$(dircolors -b ~/.dir_colors)"
# X Resources.
#[ "$DISPLAY" -a -f "$HOME/.Xdefaults" ] && \
#
exists xrdb && xrdb "$HOME/.Xdefaults"
#-------------------------#
# SHELL - COMPLETION
#
#-------------------------#
complete_getpw() {
local successes candidates
source ~/.getpw
for url in "${!urls[@]}"; do
[[ $url = $2* ]] || continue
successes=${urls["$url"]}
if (( successes )); then
COMPREPLY+=("$url")
fi
done
}
complete_pw() {
local successes candidates
source ~/.pw.conf
for host in "${!uses[@]}"; do
}
portget() {
(( $# )) || { emit -r "$0 [revision] [category/portname]"; return; }
[[ -e "${2#*/}" ]] && { ask -Ny! 'Target exists, delete?' && rm -rf "${2#*/}
" || return; }
svn co -r "$1" http://svn.macports.org/repository/macports/trunk/dports/"$2"
cd "${2#*/}"
}
#-------------------------#
# FUNCTIONS - NETWORKING #
#-------------------------#
exists lft && \
lft() {
sudo lft -S "$@" | tail -n +3 | column -t
}
svnup() {
local cRev=$(svn info | awk '/^Revision:/ { print $2 }')
[[ $cRev ]] || { emit -r "Not in a repository."; return 1; }
emit "Looking for updates to r$cRev"
svn up
local nRev=$(svn info | awk '/^Revision:/ { print $2 }')
[[ $nRev = $cRev ]] && {
emit "Nothing to update."
return
}
echo
emit "Changelog $cRev -> $nRev:"
svn log -r$((cRev+1)):$nRev | while IFS= read -r line; do
[[ $line ]] || continue
[[ $line != *[^-]* ]] && { begin=1; continue; }
if (( begin )); then
read rev _ user _ d t _ <<< "$line"
echo
echo "$bold$green$user$reset - r$bold${rev#r}$reset:
"$'\t'"($bol
d$d$reset - $bold$t$reset)"
begin=0
else
[[ $line = *:* ]] \
&& echo $'\t'"$reset- $bold$blue${line%%:*}$reset:${line#*:}" \
|| echo $'\t'"$reset- $line"
fi
done
echo
emit "To view the code diff of these updates; execute: svn diff -r$cRev:$nRe
v $(quote "$@")"
}
#-------------------------#
# FUNCTIONS - FILE SYSTEM #
#-------------------------#
cc() {