# ---------------------------------------------------------------------- # file: ~/.bashrc # author: Thayer Williams - http://cinderwick.ca # modified: July 28, 2008 # vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=sh: # ---------------------------------------------------------------------- # bash options --------------------------------------------------------- #set -o vi # vi input mode shopt -s cdable_vars # if cd arg is not valid, assumes its a var defining a dir shopt -s cdspell # autocorrects cd misspellings shopt -s checkwinsize # update the value of LINES and COLUMNS after each command if altered shopt -s cmdhist # save multi-line commands in history as single line shopt -s dotglob # include dotfiles in pathname expansion shopt -s expand_aliases # expand aliases shopt -s extglob # enable extended pattern-matching features shopt -s histappend # append to (not overwrite) the history file shopt -s hostcomplete # attempt hostname expansion when @ is at the beginning of a word shopt -s nocaseglob # pathname expansion will be treated as case-insensitive shopt -s no_empty_cmd_completion # ??? shopt -u promptvars # ??? #set -o noclobber # don't overwrite without warning? # change sorting methods [a-Z] instead of [A-Z] ------------------------ export LC_COLLATE="en_CA.utf8" # bash prompt styles --------------------------------------------------- PS1='\[\033[36m\]\u@\h:\w\$\[\e[0m\] ' #PS1="[\[\033[36m\]\u\[\033[37m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]]$ " #PS1='[\[\e[37m\]\u\[\e[31m\]@\[\e[37m\]\h\[\e[0m\]:\[\e[33m\]\w\[\e[0m\]] \$ ' #PS1='[\u@\h \W]\$ ' # default prompt # disable ^S/^Q flow control ------------------------------------------- if tty -s ; then stty -ixon stty -ixoff fi # bash history --------------------------------------------------------- export HISTFILE="$HOME/.bash_history_`hostname`" # hostname appended to bash history filename export HISTSIZE=10000 # bash history will save N commands export HISTFILESIZE=${HISTSIZE} # bash will remember N commands export HISTCONTROL=ignoreboth # ingore duplicates and spaces (ignoreboth, ignoredups, ignorespace) # don't append the following to history: consecutive duplicate # commands, ls, bg and fg, and exit HISTIGNORE='\&:fg:bg:ls:pwd:cd ..:cd ~-:cd -:cd:jobs:set -x:ls -l:ls -l' HISTIGNORE=${HISTIGNORE}':%1:%2:shutdown*' export HISTIGNORE # env vars ------------------------------------------------------------- export CDPATH=.:~/:~/work/clients # also search ~/ and clients dirs when cding export PATH=$PATH:~/bin # add ~/bin to PATH export OOO_FORCE_DESKTOP=gnome # openoffice preferences export BROWSER="links '%s' &" export INPUTRC=/etc/inputrc # define 1st and 2nd choice editors and pagers export EDITOR=/usr/bin/vi export PAGER=/bin/more my_editor=vim my_pager=less type $my_editor >/dev/null 2>&1 && export EDITOR=$my_editor type $my_pager >/dev/null 2>&1 && export PAGER=$my_pager export VISUAL=vim export PAGER=less export MANPAGER=less export MAILCHECK=0 export IGNOREEOF=3 # Ctrl-D shouldn't log out # bash sudo completion ------------------------------------------------- complete -cf sudo if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi # when connecting to SSH, start or reattach screen session ------------- if [ -n "$SSH_CONNECTION" ] && [ -z "$SCREEN_EXIST" ]; then export SCREEN_EXIST=1 screen -DR fi # aliases -------------------------------------------------------------- alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias .....="cd ../../../.." alias vi="vim" alias hist="history | grep $1" # search cmd history #alias cp="cp -i" alias df="df -h" # human-readable sizes alias du="du -h" # disk hog alias ducks="du -cks * |sort -rn |head -11" # disk hog alias free="free -m" # show sizes in MB alias ls="ls --color=auto -F" # colourized list alias ll="ls -lh" # list detailed with human-readable sizes alias la="ls -a" # list all files alias lla="ls -al" # list all files long alias lal="ls -al" # list all files long alias dir="ls -1" # windows-style list alias f="find | grep" # quick search alias c="clear" # clear screen alias xp='xprop | grep "WM_WINDOW_ROLE\|WM_CLASS" && echo "WM_CLASS(STRING) = \"NAME\", \"CLASS\""' # get xprop CLASS and NAME alias sv="sudo vim" alias sps="ps aux | grep -v grep | grep" # search process alias grep="grep --color=auto" # colourized grep alias egrep="egrep --color=auto" # colourized egrep alias fixres="xrandr --size 1680x1050" # reset resolution alias clam="clamscan --bell -i" # clamav scan a file alias clamt="clamscan -r --bell -i ~/tmp" # clamav scan ~/tmp alias getip="wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1" alias dwc="vim ~/code/dwm-5.2/config.h" alias dwmmake="cd ~/code/dwm-5.2/ && sudo make clean install && make clean && killall dwm && cd" alias obr="vim ~/.config/openbox/rc.xml" alias obm="vim ~/.config/openbox/menu.xml" alias oba="vim ~/.config/openbox/autostart.sh" alias dc="cd ~/.abs/dwm/ && vim config.h && makepkg -srcif && cd -" alias psm="echo '%CPU %MEM PID COMMAND' && ps hgaxo %cpu,%mem,pid,comm | sort -nrk1 | head -n 10 | sed -e 's/-bin//' | sed -e 's/-media-play//'" alias ntp="sudo /usr/bin/ntpdate time-a.nist.gov" # update time alias timer='time read -p "Press enter to stop"' #unalias -a # uncomment to unalias everything # ssh/encrypt aliases -------------------------------------------------- alias k="ssh-add" alias kd="ssh-add -D" source ~/.bash_private # pkgbuild aliases ----------------------------------------------------- alias vp="vim PKGBUILD" alias clean="rm -rf pkg/ src/ *~" # clean up the build dir alias svnid="svn propset svn:keywords Id PKGBUILD" # pacman aliases ------------------------------------------------------- alias pacup="sudo pacman -Syu" # sync and update alias pacin="sudo pacman -S" # install pkg alias pacout="sudo pacman -Rns" # remove pkg and the deps it installed alias pacs="pacman -Sl | cut -d' ' -f2 | grep " # alias pac="pacsearch" # colorize pacman (pacs) pacsearch () { echo -e "$(pacman -Ss $@ | sed \ -e 's#core/.*#\\033[1;31m&\\033[0;37m#g' \ -e 's#extra/.*#\\033[0;32m&\\033[0;37m#g' \ -e 's#community/.*#\\033[1;35m&\\033[0;37m#g' \ -e 's#^.*/.* [0-9].*#\\033[0;36m&\\033[0;37m#g' )" } # LESS man page colors ------------------------------------------------- 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' # linux console colors (ala phrak) ------------------------------------- if [ "$TERM" = "linux" ]; then echo -en "\e]P0000000" #black echo -en "\e]P8555753" #darkgrey echo -en "\e]P1ff6565" #darkred echo -en "\e]P9ff8d8d" #red echo -en "\e]P293d44f" #darkgreen echo -en "\e]PAc8e7a8" #green echo -en "\e]P3eab93d" #brown echo -en "\e]PBffc123" #yellow echo -en "\e]P4204a87" #darkblue echo -en "\e]PC3465a4" #blue echo -en "\e]P5ce5c00" #darkmagenta echo -en "\e]PDf57900" #magenta echo -en "\e]P689b6e2" #darkcyan echo -en "\e]PE46a4ff" #cyan echo -en "\e]P7cccccc" #lightgrey echo -en "\e]PFffffff" #white clear # bring us back to default input colours fi # functions ------------------------------------------------------------ function mkcd() { mkdir "$1" && cd "$1"; } function hex2dec { awk 'BEGIN { printf "%d\n",0x$1}'; } function dec2hex { awk 'BEGIN { printf "%x\n",$1}'; } # mktar - tarball wrapper # usage: mktar function mktar() { tar czf "${1%%/}.tar.gz" "${1%%/}/"; } # calc - simple calculator # usage: calc function calc() { echo "$*" | bc; } # search the vim reference manual for a keyword # usage: :h function :h() { vim --cmd ":silent help $@" --cmd "only"; } # mkmine - recursively change ownership to $USER:$USER # usage: mkmine, or # mkmine function mkmine() { sudo chown -R ${USER} ${1:-.}; } # remindme - a simple reminder # usage: remindme 10m "omg, the pizza" function remindme() { sleep $1 && zenity --info --text "$2" & } # nohup - run command detached from terminal and without output # usage: nh function nh() { nohup "$@" &>/dev/null & } # s - gnu screen function # usage: lists screen sessions, otherwise # s reattaches to , otherwise # s creates a new session . s () { if [[ $1 ]]; then screen -dRR -S $HOSTNAME.$1 else screen -ls fi } # x - archive extractor # usage: x x () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) rar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo "'$1' cannot be extracted via ex()" ;; esac else echo "'$1' is not a valid file" fi } # roll - archive wrapper # usage: roll ./foo ./bar roll () { 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 } # define - fetch word defnition from google # usage: define define () { lynx -dump "http://www.google.com/search?hl=en&q=define%3A+${1}&btnG=Google+Search" | grep -m 5 -w "*" | sed 's/;/ -/g' | cut -d- -f5 > /tmp/templookup.txt if [[ -s /tmp/templookup.txt ]] ;then until ! read response do echo "${response}" done < /tmp/templookup.txt else echo "Sorry $USER, I can't find the term \"${1} \"" fi rm -f /tmp/templookup.txt } # absbuild - quickly build and upgrade a pkg from ABS # usage: absbuild absbuild() { ABSPATH=`find /var/abs -type d -name $1` mkdir -p ~/.abs/$1 cp -R $ABSPATH/* ~/.abs/$1 cd ~/.abs/$1 $EDITOR PKGBUILD } # absfind - quickly locate and cat an ABS PKGBUILD # usage: absfind absfind() { ABSPATH=`find /var/abs -type d -name $1` ls $ABSPATH cat $ABSPATH/PKGBUILD } # send public key to remote server # usage: sendkey sendkey() { if [ $# -ne 1 ]; then ssh $1 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_dsa.pub fi } # start, stop, restart, reload - simple daemon management # usage: start start() { for arg in $*; do sudo /etc/rc.d/$arg start done } stop() { for arg in $*; do sudo /etc/rc.d/$arg stop done } restart() { for arg in $*; do sudo /etc/rc.d/$arg restart done } reload() { for arg in $*; do sudo /etc/rc.d/$arg reload done }