# ~/.bashrc: executed by bash(1) for non-login shells. # configured by hand # Author: Anton Winter # $Id: .bashrc 50 2007-09-19 09:57:56Z anton $ # if [ "$PS1" ]; then # If running interactively, then run till fi at EOF: if [ "x$SHLVL" != "x1" ]; then # We're not a login shell if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done fi if [ -e /etc/profile ]; then source /etc/profile fi if [ -e ~/.profile ]; then source ~/.profile fi fi # Source global definitions first if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc elif [ -f /etc/bashrc ]; then . /etc/bashrc fi if [ -d ~/bin ] ; then PATH="~/bin:${PATH}" fi # User specific aliases alias vi='vim' alias c='clear' alias cls='clear' alias m='more' alias dos2unix='perl -i.bak -pe "s/\015//"' alias unix2dos='perl -i.bak -pe "s/$/\r/"' alias sshgo='eval /usr/bin/ssh-agent $SHELL' alias sshadd='/usr/bin/ssh-add' alias ssh='ssh -C -X -A' alias ssj='ssh -X -A' # I don't know how many times i've done this typo.. alias :q!='echo do I look like vi?' alias :wq='echo do I look like vi?' alias :q='echo do I look like vi?' alias :x='echo do I look like vi?' alias rm='rm -i' alias ..='cd ..' alias cd..='cd ..' alias duck='du -ck * | sort -rn |head -20' alias dusk='du -sk * | sort -rn |head -20' alias mf='mplayer -fs' alias cvn='svn' # damn typo's :-) alias bv='grep \$Id\: ~/.bashrc' alias be='vi ~/.bashrc;source ~/.bashrc;echo;bv' alias rb='source ~/.bashrc;echo;bv' alias newpw='pwgen -n 8 -1 -s' alias newpwbofh='pwgen -n 48 -1 -s ' alias bliztime='TZ=PST8 date' alias grep='grep --colour=auto' # Environment variables export NAME="Anton Winter" export IRCNICK="myrddin" export IRCNAME="anton" export CVS_RSH="ssh" export CVSEDITOR="vim" export EDITOR="vim" export ENV=$HOME/.bashrc export PAGER="less" export LANG="en_AU" export LANGUAGE="C" export LC_COLLATE="C" export LC_ALL="C" export CVS_RSH="ssh" export RSNYC_RSH="ssh" export HISTSIZE="1000000" export HISTIGNORE="$HISTIGNORE:ls:cd:la:ll:history" export HOST=$(hostname) export OS=$(uname) # Bash settings # umask 077 umask 022 ulimit -S -c 0 # Don't want any coredumps #set -o noclobber # prevents catting over file #set -o nounset set bell-style none # Remove beeps for command completion unset MAILCHECK # goes hand in hand with shopt -u mailwarn # bash options enabled - view with shopt -p shopt -s cdspell shopt -s cdable_vars shopt -s checkhash shopt -s checkwinsize shopt -s cmdhist shopt -s dotglob shopt -s extglob shopt -s histappend shopt -s histappend histreedit histverify shopt -s hostcomplete shopt -s no_empty_cmd_completion # bash options disabled shopt -u mailwarn # this is just annoying # If running interactively, then: if [ "$PS1" ]; then # enable color support of ls and also add handy aliases eval $(dircolors -b >/dev/null 2>&1) alias ls='ls --color=auto -F' alias ll='ls -l' alias kk='ll' alias la='ls -Al --color=always |more' alias l='ls -CF' alias dir='ls -Al --color=always |more' alias vdir='ls --color=auto --format=long' export LS_OPTIONS='--color=auto' # enable bash completion in interactive shells if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi # prompt setup #export PS1="\u@\h:\w\$ " PS1="\n\[\033[0;32m\][\[\033[0;37m\]\t\[\033[0;32m\]]\n\[\033[1;32m\]\[\033[0;32m\][\[\033[0;37m\]\u@\h\[\033[0;32m\]]\[\033[0;32m\][\[\033[1;37m\]\w\[\033[0;32m\]]$\[\033[0m\] " # Black 0;30 Dark Gray 1;30 # Blue 0;34 Light Blue 1;34 # Green 0;32 Light Green 1;32 # Cyan 0;36 Light Cyan 1;36 # Red 0;31 Light Red 1;31 # Purple 0;35 Light Purple 1;35 # Brown 0;33 Yellow 1;33 # Light Gray 0;37 White 1;37 red='\e[0;31m' RED='\e[1;31m' blue='\e[0;34m' BLUE='\e[1;34m' cyan='\e[0;36m' CYAN='\e[1;36m' green='\e[0;32m' GREEN='\e[1;32m' NC='\e[0m' #no color # Set xtitle if [ "$TERM" != "linux" ]; then #PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"' PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}\007"' export PROMPT_COMMAND fi # mail stuff if [ -d ~/Maildir/ ]; then export MAIL=~/Maildir/ export MAILDIR=~/Maildir/ elif [ -f /var/mail/${USER} ]; then export MAIL="/var/mail/${USER}" fi #################################### # Functions # dokeychainmagic() { sshagent=$(ps auxww|egrep -v 'grep|defunct|gnome-session|dbus-launch'|grep ^${USER}|grep -i ssh-agent|wc -l) keychain=$(which keychain) if [ -x ${keychain} ] && [ -f $HOME/.ssh/id_dsa ] && [ "$sshagent" -le "1" ]; then ${keychain} $HOME/.ssh/id_dsa --quiet source $HOME/.keychain/${HOST}-sh else if [ -f $HOME/.keychain/${HOST}-sh ] && [ "$sshagent" -ge "1" ]; then source $HOME/.keychain/${HOST}-sh fi fi } term() { # Change terminal type TERM=$1 export TERM tset } # Host specific dvdrw & cdrw device locations # these variables are required in some of the # following functions case "${HOSTNAME}" in "anubis" ) cdromdev="dev=ATA:1,0,0" ;; "ashrak" ) cdromdev="dev=ATAPI:0,0,0" ;; esac burniso() { # Take a guess... sudo su -c "cdrecord driveropts=burnfree -v -pad ${cdromdev} -eject $*" # -dao } burnfiles() { sudo su -c "mkisofs -R $* | cdrecord driveropts=burnfree -v ${cdromdev} -eject -multi -" } blankcdrw() { sudo su -c "cdrecord driveropts=burnfree -v ${cdromdev} -eject blank=fast" } createdvdiso() { # create a dvd iso from files on disk mkisofs -r -J -o $* # usage: createdvdiso filename.iso /files/to.burn } createiso() { if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "create an iso" echo "usage: createiso /dev/cdrom output.file.iso" else dd if=${1} of=${2} bs=2048 count=$(/sbin/isosize -d 2048 ${1}) fi } burnisodvd() { growisofs -dvd-compat -Z /dev/dvd=$* } dvdrwnew() { # start a new dvdrw disk growisofs -Z /dev/dvd -R -J "$*" } dvdrwadd() { # add to an existing dvdrw disk growisofs -M /dev/dvd -R -J $* } fsync() { # fast sync? Cause that way I do not have to remember the switches ;) rsync -avze ssh --progress --rsh=ssh $* } xtitle () { # set the title of an x term echo -n -e "\033]0;$*\007" } lu() { (/bin/ls -lt $* | head -15) 2>/dev/null echo " . . ." } mostused() { # what is the most used command for this session? hash| grep -v hits|sort -nr|head -n1 } bigfile() { # creates a big file - syntax: "bigfile NNN" NNN = size in megabytes if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "create a big file" echo "usage: bigfile [ size ] where size = size in megabytes" else dd if=/dev/zero of=bigfile bs=1M count=$* fi } distcc-enable() { if [ -n "$PATH2" ] ; then distccstatus=$(echo "${PATH}" | grep -q distcc ; echo $?) if [ "${distccstatus}" -gt 0 ] ; then echo "distcc has already been enabled, distcc found in $PATH" else echo "\$PATH2 found, but distcc doesn't appear to be in \$PATH... something weird is going on" fi else export PATH2="${PATH}" export PATH="/usr/local/distcc/bin:${PATH}" fi } distcc-disable() { export PATH="${PATH2}" unset PATH2 } netinf() { netstat -tan|grep "^tcp"|awk '{print $6}'|sort|uniq -c|sort -n } watchtv () { # tv channel_name - where channel name is in ~/.mplayer/channels.conf mplayer dvb://$* } watchtv2() { # tv channel_name - where channel name is in ~/.mplayer/channels.conf #mplayer -vf dvbscale,expand=-1:576:-1:-1:1,scale=-1:0,softskip dvb://$* mplayer -vf dvbscale,scale=-1:0,softskip dvb://$* } #recordtv() { # recordtv channel filename # tv channel_name - where channel name is in ~/.mplayer/channels.conf # filename, where the stream is going to be saved to # mencoder -ovc lavc -oac mp3lame -lameopts abr:br=128 -lavcopts acodec=mp3:vcodec=mpeg4:vbitrate=1800 -vf dvbscale,scale=720:480,denoise3d dvb://$1 -o $2 # } encode-xvid() { rm -fv ./xvid-twopass.stats mencoder $1 -oac copy -ovc xvid -xvidencopts pass=1:vhq=4:me_quality=6:chroma_me:quant_type=h263:max_bframes=2 -o /dev/null mencoder $1 -oac copy -ovc xvid -xvidencopts pass=2:vhq=4:me_quality=6:chroma_me:quant_type=h263:max_bframes=2 -o $2 } channels() { cat ~/.mychannels.conf | awk -F: '{print $1}' } pskill() { local pid pid=$(ps -ax | grep $1 | grep -v grep | awk '{ print $1 }') echo -n "killing $1 (process $pid)..." kill -9 $pid echo "dead." } rot13() { if [ $# = 0 ] ; then tr "[a-m][n-z][A-M][N-Z]" "[n-z][a-m][N-Z][A-M]" else tr "[a-m][n-z][A-M][N-Z]" "[n-z][a-m][N-Z][A-M]" < $1 fi } ips() { if [ -x /sbin/ip ] then for iface in $(ip -f inet addr|grep ^[0-9]|awk '{print $2}') do echo "${iface} $(ip -f inet addr show ${iface}| grep inet|awk '{print $2}')" done else for iface in $(/sbin/ifconfig|grep inet| grep -v inet6|awk -Faddr: '{print $2}'| awk '{print $1}') do echo ${iface} done fi } function ii() { # get current host related info # kind of works on mac. different interface. dynamic-able? echo -e "\nYou are logged onto ${RED}$HOST" echo -e "\nAdditionnal information:$NC " ; uname -a echo -e "\n${RED}Users logged on:$NC " ; w -h echo -e "\n${RED}Current date :$NC " ; date echo -e "\n${RED}Machine stats :$NC " ; uptime echo -e "\n${RED}Memory stats :$NC " ; free echo -e "\n${RED}CPU :$NC " ; grep "model name" /proc/cpuinfo|awk -F:\ '{print $2}' echo -e "\n${RED}IP Addresses :$NC " ; ips } movein() { if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "move your dotfiles into a remote host" echo "usage: movein [ hostname|ip address ]" else if [ ! -d ~/.skel ]; then echo "~/.skel missing, creating a basic one for you.." mkdir -p ~/.skel/{bin,.ssh} chmod 700 ~/.skel/.ssh ln -s ~/.bashrc ~/.skel/ ln -s ~/.bash_profile ~/.skel/ ln -s ~/.screenrc ~/.skel/ ln -s ~/.vimrc ~/.skel/ ln -s ~/.ssh/authorized_keys ~/.skel/.ssh/ fi cd ~/.skel tar zhcf - . | ssh $1 "tar zpvxf -" 2>/dev/null cd ${OLDPWD} fi } sendbashrc() { if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "copy your .bashrc to a remote host" echo "usage: sendbashrc [ hostname|ip address ]" else scp ~/.bashrc $1:~/.bashrc fi } getbashrc() { # get a new copy of .bashrc from svn d1="$(pwd)" d2="/var/tmp/$(date +%Y%m%d-%H%M%S)" mkdir -p ${d2} cd ${d2} if [ ! -x "$(which svn)" ] then echo "You do not appear to have an svn client installed!" else echo -en "Getting a copy of .bashrc from svn... " svn checkout https://tokra.atlantis.myrddin.org/svn/atlantis/home/ >/dev/null cp home/.bashrc ~/ && echo -e "done" [ -d ${d2} ] && rm -rf ${d2} fi cd "${d1}" unset d1 d2 source ~/.bashrc echo grep \$Id\: ~/.bashrc } uc() { echo -e "${RED}Users connected:$NC " if [ "$OS" = "Linux" ]; then w -sh|sort elif [ "$OS" = "FreeBSD" ]; then w -h|sort fi } psgrep() { if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "grep running processes" echo "usage: psg [process]" else ps aux | grep -v grep | egrep "USER|$1" fi } repeat() { if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "repeat things" echo "usage: repeat n command" else local i max max=$1; shift; for ((i=1; i <= max ; i++)); do eval "$@"; done fi } www() { elinks http://$1 } gg() { echo "searching google for $*" SEARCH=$(echo $* | sed -e 's/ /\%20/g') echo "translating search to URL speak... $SEARCH" www www.google.com/search?q="$SEARCH" } lowercase() { for file ; do filename=${file##*/} case "$filename" in */*) dirname==${file%/*} ;; *) dirname=.;; esac nf=$(echo $filename | tr A-Z a-z) newname="${dirname}/${nf}" if [ "$nf" != "$filename" ]; then mv "$file" "$newname" echo "lowercase: $file --> $newname" else echo "lowercase: $file not changed." fi done } vim2html() { if [ $# -lt 1 ] || [ $# -gt 2 ]; then echo "vim syntax highlighting to html" echo "usage: vim2html filename" else vim -n -c ':so $VIMRUNTIME/syntax/2html.vim' -c ':wqa' $1 > /dev/null 2> /dev/null fi } mvbak() { timestamp="$(date +%Y%m%d-%H%M-%S)" if [ -f "$1" ]; then echo "copying ${1} to ${1}.${timestamp}.mvbak" cp ${1} ${1}.${timestamp}.mvbak else echo "File ${1} does not exist." fi } ti() { daysold=14 i_daysold=90 if [ -f ${1} ]; then mvbak ${1} for fname in $(find ${1}*.mvbak -type f -links 1 -ctime +${i_daysold} -print); do echo Auto Deleting ${fname} "(older than ${i_daysold} days)" rm -f ${fname} done for fname in $(find ${1}*.mvbak -type f -links 1 -ctime +${daysold} -print); do echo Deleting ${fname} "(older than ${daysold} days)" rm -i ${fname} done fi } avi2ipod() { fn="${1}" if [ -f ${fn} ]; then out="$(echo ${fn}|sed 's/avi$/mp4/')" ffmpeg -i ${fn} -f mp4 -vcodec mpeg4 \ -maxrate 2000 -b 1500 -qmin 3 -qmax 5 -bufsize 4096 -g 300 \ -acodec aac -ar 44100 -ab 128 -s 320x180 -aspect 16:9 \ ${out} fi } nobeeps() { # console beeps really annoy me, so lets get rid of em! setterm -blength 0 } psc() { ps --cols=1000 --sort='-%cpu,uid,pgid,ppid,pid' -e \ -o user,pid,ppid,pgid,stime,stat,wchan,time,pcpu,pmem,vsz,rss,sz,args | sed 's/^/ /' | less } psm() { ps --cols=1000 --sort='-vsz,uid,pgid,ppid,pid' -e \ -o user,pid,ppid,pgid,stime,stat,wchan,time,pcpu,pmem,vsz,rss,sz,args | sed 's/^/ /' | less } tcpstates() { netstat -tan | grep "^tcp" | cut -c 68- | sort | uniq -c | sort -n } #################################### # Host related stuff # if [ "$PS1" -a "$UID" != 0 ]; then #if [ "x$SHLVL" = "x1" ]; then # We're not a login shell case "${HOSTNAME}" in "anubis" ) dokeychainmagic nobeeps export DISTCC_HOSTS="zatarc localhost" export CONCURRENCY_LEVEL="8" export BROWSER="firefox" #export __GL_SINGLE_THREADED="1" # fixes doom3 GL bug export MPD_HOST="music" export MPD_PORT="6600" export DEBEMAIL="anton@myrddin.org" export DEBFULLNAME="Anton Winter" export SSH_ASKPASS="/usr/bin/ssh-askpass" alias erasetape='td="/dev/nst0"; time (mt -f ${td} rewind;mt -f ${td} erase; mt -f ${td} rewoffl)' alias wowace='acedir=/mnt/storage/games/wow/ace; if [ -d ${acedir} ] ; then cd ${acedir}; ./get-ace2-updates.pl && ./install.sh; else echo "unable to access ${acedir}"; fi; cd ${OLDPWD}' alias tv="test -d /mnt/media/tv/ && cd /mnt/media/tv/" ;; "zatarc" ) dokeychainmagic export DISTCC_HOSTS="anubis localhost" export CONCURRENCY_LEVEL="8" export SSH_ASKPASS="/usr/bin/ssh-askpass" uc ;; "tokra" ) dokeychainmagic uc fix-svn() { for dir in $(find /home/svn -maxdepth 1 -mindepth 1 -type d) do echo "* Recovering ${dir}" svnadmin recover ${dir} echo "" done } export SSH_ASKPASS="/usr/bin/ssh-askpass" alias tv="test -d /home/media/tv/ && cd /home/media/tv/" ;; "daedalus" | "prometheus" | "beliskner" ) dokeychainmagic export CVS_RSH=ssh export CVSROOT="" doproxy() { export http_proxy="http://dpsquid2.web.fairfax.com.au:8080" export https_proxy="${http_proxy}" export ftp_proxy="${http_proxy}" } undoproxy() { unset {http{,s},ftp}_proxy } uc ;; "sibum" | "sibum.pair.com" ) alias ls='ls ' alias ll='ls -l' alias la='ls -Al |more' alias l='ls -CF' alias dir='ls -Al |more' alias vdir='ls --format=long' unalias grep unset LS_OPTIONS unset LOCALE uc ;; "mailer1" ) alias vim='vi' uc ;; "othalla" | "othalla.atlantis.myrddin.org" ) unalias ls alias ssh='ssh -C -A' dokeychainmagic uc ;; * ) uc ;; # # End of host related tests esac echo "" uptime fi #fi #################################### fi