k0scist@0: source /etc/profile k0scist@0: k0scist@0: # Test for an interactive shell. There is no need to set anything k0scist@0: # past this point for scp and rcp, and it's important to refrain from k0scist@0: # outputting anything in those cases. k0scist@0: if [[ $- != *i* ]] ; then k0scist@0: # Shell is non-interactive. Be done now! k0scist@0: return k0scist@0: fi k0scist@0: k0scist@0: # Enable colors for ls, etc. Prefer ~/.dir_colors #64489 k0scist@0: if [[ -f ~/.dir_colors ]] ; then k0scist@0: eval $(dircolors -b ~/.dir_colors) k0scist@0: elif [[ -f /etc/DIR_COLORS ]] ; then k0scist@0: eval $(dircolors -b /etc/DIR_COLORS) k0scist@0: fi k0scist@0: jhammel@67: # variables k0scist@0: export CLICOLOR=1 k0scist@0: export EDITOR='emacs -nw' jhammel@171: export MOZCONFIG=~/mozilla/mozconfigs/mozconfig jhammel@88: export MOZSOURCE=~/mozilla/src/mozilla-central jhammel@88: export MOZOBJ=~/mozilla/src/obj-browser jhammel@86: export JS_EDITLINE=1 k0scist@0: k0scist@0: # aliases k0scist@0: alias ls='ls --color=auto' k0scist@0: alias grep='grep --colour=auto' k0scist@0: alias wget='wget --no-check-certificate' k0scist@0: alias datestamp='date +%Y%m%d%H%M%S' k0scist@0: alias svnst='svn st | grep -v "^\?"' k0scist@0: alias awd="python -c 'import os; print os.path.realpath(\".\")'" k0scist@10: alias distribute='python setup.py egg_info -RDb "" sdist register upload' k0scist@0: alias random="python -c 'import sys, random; foo = sys.argv[1:]; random.shuffle(foo); print \" \".join(foo)'" jhammel@88: alias xpcshell="LD_LIBRARY_PATH=${MOZOBJ}/dist/bin ${MOZOBJ}/dist/bin/xpcshell" jhammel@215: alias mozharness-bug="bz new 'Release Engineering: Automation (General)' --cc ':aki' --whiteboard 'mozharness'" jhammel@217: alias talos-bug="bz new Talos --cc ':jmaher' --cc ':BYK'" k0scist@0: jhammel@66: # PROMPT jhammel@119: PS1='│' jhammel@119: PS2='.' k0scist@0: PROMPT_COMMAND='echo -ne "\033]0;${SSH_CLIENT/*/$HOSTNAME:}${PWD/~/~}\007"' k0scist@0: jhammel@66: # PATHs jhammel@147: export PATH=~/firefox:~/bin:~/python:$PATH:/usr/sbin:/usr/games/bin jhammel@169: export PYTHONPATH=~/python:$PYTHONPATH:~/virtualenv k0scist@0: jhammel@66: jhammel@84: ### functions jhammel@84: k0scist@0: cdwin() { jhammel@71: # change directory to a window's location using its title k0scist@0: DIR=$(xwininfo | dictify.py xwininfo | awk '{ print $NF }' | sed 's/"//g') k0scist@0: DIR=${DIR/\~/$HOME} k0scist@0: cd $DIR k0scist@0: } k0scist@0: k0scist@0: eend() { jhammel@71: # edit the end of a file with emacs k0scist@0: FILE=$1 k0scist@0: shift k0scist@0: emacs +`wc -l "$FILE"` $@ k0scist@0: } k0scist@0: jhammel@144: git-diff-master() { jhammel@144: git diff $(git merge-base HEAD master) jhammel@144: } jhammel@144: jhammel@66: function colors() { jhammel@66: jhammel@66: CLR_WHITE="\033[0;37m" jhammel@66: CLR_WHITEBOLD="\033[1;37m" jhammel@66: CLR_BLACK="\033[0;30m" jhammel@66: CLR_GRAY="\033[1;30m" jhammel@66: CLR_BLUE="\033[1;34m" jhammel@66: CLR_BLUEBOLD="\033[0;34m" jhammel@66: CLR_GREEN="\033[0;32m" jhammel@66: CLR_GREENBOLD="\033[1;32m" jhammel@66: CLR_CYAN="\033[0;36m" jhammel@66: CLR_CYANBOLD="\033[1;36m" jhammel@66: CLR_RED="\033[0;31m" jhammel@66: CLR_REDBOLD="\033[1;31m" jhammel@66: CLR_PURPLE="\033[0;35m" jhammel@66: CLR_PURPLEBOLD="\033[1;35m" jhammel@66: CLR_YELLOW="\033[0;33m" jhammel@66: CLR_YELLOWBOLD="\033[1;33m" jhammel@66: CLR_NOTHING="\033[0m" jhammel@66: } jhammel@66: colors jhammel@66: k0scist@0: # nice fast find function k0scist@0: EXCLUDES="(\.svn)|(\.mo$)|(\.po$)|(\.pyc$)" k0scist@0: ff() { k0scist@0: k0scist@0: if (( $# < 2 )) k0scist@0: then k0scist@0: FILENAME='*' # default -- look in all files k0scist@0: else k0scist@0: FILENAME=$2 k0scist@0: fi jhammel@76: CMD='command find -L $PWD -iname "${FILENAME}" -print0 2> /dev/null | xargs -r0 grep -il "$1" 2> /dev/null | egrep -v "${EXCLUDES}" 2> /dev/null' k0scist@0: # echo $CMD k0scist@0: eval $CMD k0scist@0: k0scist@0: } k0scist@0: k0scist@0: chainff() { k0scist@0: if (( $# < 2 )) k0scist@0: then k0scist@0: return 0 k0scist@0: fi k0scist@0: k0scist@0: RESULTS=`ff "$2" "$1"` k0scist@0: shift 2 k0scist@0: k0scist@0: for i in $RESULTS k0scist@0: do k0scist@0: for arg in $@ k0scist@0: do k0scist@0: if grep -il "$arg" "$i" &> /dev/null k0scist@0: then k0scist@0: touch /dev/null k0scist@0: else k0scist@0: i="" k0scist@0: break k0scist@0: fi k0scist@0: done k0scist@0: if [ -n "$i" ] k0scist@0: then k0scist@0: echo $i k0scist@0: fi k0scist@0: done k0scist@0: } k0scist@0: jhammel@66: # contextual fastfind jhammel@66: cff () { jhammel@66: jhammel@66: if (( $# < 2 )); then jhammel@66: local FILENAME='*' # default -- look in all files jhammel@66: else jhammel@66: local FILENAME=$2 jhammel@66: fi jhammel@66: jhammel@66: for i in `ff "$1" "$FILENAME"`; do jhammel@66: echo -e "$CLR_GREEN--->>> ""$CLR_YELLOWBOLD""$i""$CLR_NOTHING" : jhammel@66: grep --color=auto -i -n -C 3 "$1" $i jhammel@66: done jhammel@66: jhammel@66: } jhammel@66: jhammel@66: # make a temporary file k0scist@0: tmpfile() { k0scist@0: k0scist@0: if [ "$#" == "0" ] k0scist@0: then jhammel@103: args="tmp" k0scist@0: else k0scist@0: args=$@ k0scist@0: fi k0scist@0: k0scist@0: for i in $args k0scist@0: do k0scist@0: NEWNAME=${i}.$RANDOM k0scist@0: k0scist@0: while [ -e $NEWNAME ] k0scist@0: do k0scist@0: NEWNAME=${NEWNAME}.tmp k0scist@0: done k0scist@0: echo "$NEWNAME" k0scist@0: done k0scist@0: } k0scist@0: k0scist@0: edpe() { k0scist@0: # edit and pipe the buffer to stdout k0scist@0: FILE=`tmpfile` k0scist@0: $EDITOR $FILE k0scist@0: cat $FILE k0scist@0: rm $FILE k0scist@0: } k0scist@0: k0scist@0: swap() { jhammel@71: # swap two files k0scist@0: if [ "$#" != "2" ] k0scist@0: then k0scist@0: echo "Usage: $FUNCNAME " k0scist@0: return k0scist@0: fi k0scist@0: for i in "$1" "$2" k0scist@0: do k0scist@0: if [ ! -w "$i" ] k0scist@0: then k0scist@0: echo "$FUNCNAME: Can't move $i" k0scist@0: return 1 k0scist@0: fi k0scist@0: done k0scist@0: k0scist@0: NEWNAME=`basename $1`.$RANDOM k0scist@0: k0scist@0: while [ -e $NEWNAME ] k0scist@0: do k0scist@0: NEWNAME=${NEWNAME}.tmp k0scist@0: echo "$NEWNAME" k0scist@0: done k0scist@0: k0scist@0: mv `basename $1` $NEWNAME k0scist@0: mv `basename $2` `basename $1` k0scist@0: mv $NEWNAME `basename $2` k0scist@0: } k0scist@0: k0scist@0: isrunning() { jhammel@71: # is a process running? (by name) k0scist@0: for i in "$@" k0scist@0: do k0scist@0: ps axwww | grep "$i" | grep -v 'grep' k0scist@0: done | sort | uniq k0scist@0: k0scist@0: } k0scist@0: k0scist@0: killbyname() { jhammel@71: # kill a process by name k0scist@0: kill `isrunning "$@" | awk '{ print $1 }' | onelineit.py` k0scist@0: } k0scist@0: k0scist@0: k0scist@0: tf() { k0scist@0: if [[ $@ ]] k0scist@0: then k0scist@0: echo "true" k0scist@0: else k0scist@0: echo "false" k0scist@0: fi k0scist@0: } k0scist@0: k0scist@0: # full name k0scist@0: fn() { k0scist@0: python -c "import os; print os.path.realpath('$*')" k0scist@0: } k0scist@0: k0scist@0: # which view k0scist@0: whview() { k0scist@0: less `which $@` k0scist@0: } k0scist@0: jhammel@66: # which emacs k0scist@0: whemacs() { k0scist@0: emacs -nw `which $@` k0scist@0: } k0scist@0: k0scist@0: pyfile() { jhammel@71: # python file name k0scist@0: python -c "import $1; print $1.__file__" k0scist@0: } k0scist@0: k0scist@0: svndance(){ jhammel@71: # do the svn import dance! k0scist@0: if (( $# )) k0scist@0: then k0scist@0: svn import $1 k0scist@0: cd .. k0scist@0: rm -rf $OLDPWD k0scist@0: svn co $1 $OLDPWD k0scist@0: cd $OLDPWD k0scist@0: else k0scist@0: return 1 k0scist@0: fi k0scist@0: } k0scist@0: jhammel@71: difffiles() { jhammel@71: grep '^+++ ' $@ | sed 's/+++ b\///' jhammel@71: } jhammel@71: jhammel@84: hg-update-all() { jhammel@84: for i in *; jhammel@84: do jhammel@84: if [ -e $i/.hg ] jhammel@84: then jhammel@84: cd $i jhammel@84: hg pull jhammel@84: hg update jhammel@84: cd - jhammel@84: fi jhammel@84: done jhammel@84: } jhammel@84: jhammel@110: hg-qcommit() { jhammel@110: message=$1 jhammel@110: hg qrefresh jhammel@110: if [ -z "${message}" ] jhammel@110: then jhammel@110: hg qcommit jhammel@110: else jhammel@110: hg qcommit -m "${message}" jhammel@110: fi jhammel@110: hgroot=$(hg root) jhammel@110: patches=${hgroot}/.hg/patches/ jhammel@110: if [ -e ${patches}.hg ] jhammel@110: then jhammel@110: cd ${patches} jhammel@110: hg push jhammel@110: fi jhammel@111: cd - jhammel@110: } jhammel@110: jhammel@90: blog-file() { jhammel@90: echo "$HOME/web/blog/k0s/entries/public/$1" jhammel@90: } jhammel@90: jhammel@89: hgrc() { jhammel@89: ROOT="${1}" jhammel@89: echo "[paths]" jhammel@89: echo "default = ${ROOT}" jhammel@89: echo "default-push = ssh://${ROOT#http*://}" jhammel@89: } jhammel@89: jhammel@101: flatten() { jhammel@101: directory=$PWD jhammel@101: if [ "$#" == "1" ] jhammel@101: then jhammel@101: directory=$1 jhammel@101: fi jhammel@101: cd $directory jhammel@101: unset find # don't use the alias jhammel@102: find . -name '*' -type f | sed 's/.\///' | while read line jhammel@101: do jhammel@101: filename=$(echo $line | sed 's/\//-/g') jhammel@101: mv "${line}" "${filename}" jhammel@101: done jhammel@101: for i in * jhammel@101: do jhammel@101: if [ -d $i ] jhammel@101: then jhammel@101: rm -rf "${i}" jhammel@101: fi jhammel@101: done jhammel@101: } jhammel@101: jhammel@103: filehandles() { jhammel@103: TMPFILE=$(tmpfile) jhammel@103: ps -e|grep -v TTY|awk {'print "echo -n \"Process: "$4"\tPID: "$1"\tNumber of FH: \"; lsof -p "$1"|wc -l"'} > ${TMPFILE} jhammel@103: . ${TMPFILE} | sort jhammel@103: rm ${TMPFILE} jhammel@103: } jhammel@103: jhammel@167: quotemail() { jhammel@167: jhammel@167: command='s/^/> /' jhammel@167: inplace="" jhammel@167: if [ "$#" == "2" ] jhammel@167: then jhammel@167: inplace="-i" jhammel@167: fi jhammel@167: jhammel@167: sed ${inplace} "${command}" "$1" jhammel@167: jhammel@167: } jhammel@167: k0scist@0: ### include overrides for commands k0scist@0: source ~/.bash_overrides k0scist@47: k0scist@47: ### regenerate fluxbox menus here for convenience k0scist@47: MENU=~/web/site/programs.html jhammel@237: regeneratefluxmenu() { k0scist@47: if [ -e $MENU ] k0scist@47: then k0scist@47: html2flux.py $MENU > ~/.fluxbox/applications jhammel@222: fi jhammel@237: } jhammel@237: jhammel@237: regeneratefluxmenu