annotate .bashrc @ 237:b33d0c78132c

move menu regeneration to its own function
author Jeff Hammel <jhammel@mozilla.com>
date Thu, 09 Aug 2012 15:12:26 -0700
parents 57677a2bf772
children a5a27ec28ea7
rev   line source
k0scist@0 1 source /etc/profile
k0scist@0 2
k0scist@0 3 # Test for an interactive shell. There is no need to set anything
k0scist@0 4 # past this point for scp and rcp, and it's important to refrain from
k0scist@0 5 # outputting anything in those cases.
k0scist@0 6 if [[ $- != *i* ]] ; then
k0scist@0 7 # Shell is non-interactive. Be done now!
k0scist@0 8 return
k0scist@0 9 fi
k0scist@0 10
k0scist@0 11 # Enable colors for ls, etc. Prefer ~/.dir_colors #64489
k0scist@0 12 if [[ -f ~/.dir_colors ]] ; then
k0scist@0 13 eval $(dircolors -b ~/.dir_colors)
k0scist@0 14 elif [[ -f /etc/DIR_COLORS ]] ; then
k0scist@0 15 eval $(dircolors -b /etc/DIR_COLORS)
k0scist@0 16 fi
k0scist@0 17
jhammel@67 18 # variables
k0scist@0 19 export CLICOLOR=1
k0scist@0 20 export EDITOR='emacs -nw'
jhammel@171 21 export MOZCONFIG=~/mozilla/mozconfigs/mozconfig
jhammel@88 22 export MOZSOURCE=~/mozilla/src/mozilla-central
jhammel@88 23 export MOZOBJ=~/mozilla/src/obj-browser
jhammel@86 24 export JS_EDITLINE=1
k0scist@0 25
k0scist@0 26 # aliases
k0scist@0 27 alias ls='ls --color=auto'
k0scist@0 28 alias grep='grep --colour=auto'
k0scist@0 29 alias wget='wget --no-check-certificate'
k0scist@0 30 alias datestamp='date +%Y%m%d%H%M%S'
k0scist@0 31 alias svnst='svn st | grep -v "^\?"'
k0scist@0 32 alias awd="python -c 'import os; print os.path.realpath(\".\")'"
k0scist@10 33 alias distribute='python setup.py egg_info -RDb "" sdist register upload'
k0scist@0 34 alias random="python -c 'import sys, random; foo = sys.argv[1:]; random.shuffle(foo); print \" \".join(foo)'"
jhammel@88 35 alias xpcshell="LD_LIBRARY_PATH=${MOZOBJ}/dist/bin ${MOZOBJ}/dist/bin/xpcshell"
jhammel@215 36 alias mozharness-bug="bz new 'Release Engineering: Automation (General)' --cc ':aki' --whiteboard 'mozharness'"
jhammel@217 37 alias talos-bug="bz new Talos --cc ':jmaher' --cc ':BYK'"
k0scist@0 38
jhammel@66 39 # PROMPT
jhammel@119 40 PS1='│'
jhammel@119 41 PS2='.'
k0scist@0 42 PROMPT_COMMAND='echo -ne "\033]0;${SSH_CLIENT/*/$HOSTNAME:}${PWD/~/~}\007"'
k0scist@0 43
jhammel@66 44 # PATHs
jhammel@147 45 export PATH=~/firefox:~/bin:~/python:$PATH:/usr/sbin:/usr/games/bin
jhammel@169 46 export PYTHONPATH=~/python:$PYTHONPATH:~/virtualenv
k0scist@0 47
jhammel@66 48
jhammel@84 49 ### functions
jhammel@84 50
k0scist@0 51 cdwin() {
jhammel@71 52 # change directory to a window's location using its title
k0scist@0 53 DIR=$(xwininfo | dictify.py xwininfo | awk '{ print $NF }' | sed 's/"//g')
k0scist@0 54 DIR=${DIR/\~/$HOME}
k0scist@0 55 cd $DIR
k0scist@0 56 }
k0scist@0 57
k0scist@0 58 eend() {
jhammel@71 59 # edit the end of a file with emacs
k0scist@0 60 FILE=$1
k0scist@0 61 shift
k0scist@0 62 emacs +`wc -l "$FILE"` $@
k0scist@0 63 }
k0scist@0 64
jhammel@144 65 git-diff-master() {
jhammel@144 66 git diff $(git merge-base HEAD master)
jhammel@144 67 }
jhammel@144 68
jhammel@66 69 function colors() {
jhammel@66 70
jhammel@66 71 CLR_WHITE="\033[0;37m"
jhammel@66 72 CLR_WHITEBOLD="\033[1;37m"
jhammel@66 73 CLR_BLACK="\033[0;30m"
jhammel@66 74 CLR_GRAY="\033[1;30m"
jhammel@66 75 CLR_BLUE="\033[1;34m"
jhammel@66 76 CLR_BLUEBOLD="\033[0;34m"
jhammel@66 77 CLR_GREEN="\033[0;32m"
jhammel@66 78 CLR_GREENBOLD="\033[1;32m"
jhammel@66 79 CLR_CYAN="\033[0;36m"
jhammel@66 80 CLR_CYANBOLD="\033[1;36m"
jhammel@66 81 CLR_RED="\033[0;31m"
jhammel@66 82 CLR_REDBOLD="\033[1;31m"
jhammel@66 83 CLR_PURPLE="\033[0;35m"
jhammel@66 84 CLR_PURPLEBOLD="\033[1;35m"
jhammel@66 85 CLR_YELLOW="\033[0;33m"
jhammel@66 86 CLR_YELLOWBOLD="\033[1;33m"
jhammel@66 87 CLR_NOTHING="\033[0m"
jhammel@66 88 }
jhammel@66 89 colors
jhammel@66 90
k0scist@0 91 # nice fast find function
k0scist@0 92 EXCLUDES="(\.svn)|(\.mo$)|(\.po$)|(\.pyc$)"
k0scist@0 93 ff() {
k0scist@0 94
k0scist@0 95 if (( $# < 2 ))
k0scist@0 96 then
k0scist@0 97 FILENAME='*' # default -- look in all files
k0scist@0 98 else
k0scist@0 99 FILENAME=$2
k0scist@0 100 fi
jhammel@76 101 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 102 # echo $CMD
k0scist@0 103 eval $CMD
k0scist@0 104
k0scist@0 105 }
k0scist@0 106
k0scist@0 107 chainff() {
k0scist@0 108 if (( $# < 2 ))
k0scist@0 109 then
k0scist@0 110 return 0
k0scist@0 111 fi
k0scist@0 112
k0scist@0 113 RESULTS=`ff "$2" "$1"`
k0scist@0 114 shift 2
k0scist@0 115
k0scist@0 116 for i in $RESULTS
k0scist@0 117 do
k0scist@0 118 for arg in $@
k0scist@0 119 do
k0scist@0 120 if grep -il "$arg" "$i" &> /dev/null
k0scist@0 121 then
k0scist@0 122 touch /dev/null
k0scist@0 123 else
k0scist@0 124 i=""
k0scist@0 125 break
k0scist@0 126 fi
k0scist@0 127 done
k0scist@0 128 if [ -n "$i" ]
k0scist@0 129 then
k0scist@0 130 echo $i
k0scist@0 131 fi
k0scist@0 132 done
k0scist@0 133 }
k0scist@0 134
jhammel@66 135 # contextual fastfind
jhammel@66 136 cff () {
jhammel@66 137
jhammel@66 138 if (( $# < 2 )); then
jhammel@66 139 local FILENAME='*' # default -- look in all files
jhammel@66 140 else
jhammel@66 141 local FILENAME=$2
jhammel@66 142 fi
jhammel@66 143
jhammel@66 144 for i in `ff "$1" "$FILENAME"`; do
jhammel@66 145 echo -e "$CLR_GREEN--->>> ""$CLR_YELLOWBOLD""$i""$CLR_NOTHING" :
jhammel@66 146 grep --color=auto -i -n -C 3 "$1" $i
jhammel@66 147 done
jhammel@66 148
jhammel@66 149 }
jhammel@66 150
jhammel@66 151 # make a temporary file
k0scist@0 152 tmpfile() {
k0scist@0 153
k0scist@0 154 if [ "$#" == "0" ]
k0scist@0 155 then
jhammel@103 156 args="tmp"
k0scist@0 157 else
k0scist@0 158 args=$@
k0scist@0 159 fi
k0scist@0 160
k0scist@0 161 for i in $args
k0scist@0 162 do
k0scist@0 163 NEWNAME=${i}.$RANDOM
k0scist@0 164
k0scist@0 165 while [ -e $NEWNAME ]
k0scist@0 166 do
k0scist@0 167 NEWNAME=${NEWNAME}.tmp
k0scist@0 168 done
k0scist@0 169 echo "$NEWNAME"
k0scist@0 170 done
k0scist@0 171 }
k0scist@0 172
k0scist@0 173 edpe() {
k0scist@0 174 # edit and pipe the buffer to stdout
k0scist@0 175 FILE=`tmpfile`
k0scist@0 176 $EDITOR $FILE
k0scist@0 177 cat $FILE
k0scist@0 178 rm $FILE
k0scist@0 179 }
k0scist@0 180
k0scist@0 181 swap() {
jhammel@71 182 # swap two files
k0scist@0 183 if [ "$#" != "2" ]
k0scist@0 184 then
k0scist@0 185 echo "Usage: $FUNCNAME <first_arg> <second_arg>"
k0scist@0 186 return
k0scist@0 187 fi
k0scist@0 188 for i in "$1" "$2"
k0scist@0 189 do
k0scist@0 190 if [ ! -w "$i" ]
k0scist@0 191 then
k0scist@0 192 echo "$FUNCNAME: Can't move $i"
k0scist@0 193 return 1
k0scist@0 194 fi
k0scist@0 195 done
k0scist@0 196
k0scist@0 197 NEWNAME=`basename $1`.$RANDOM
k0scist@0 198
k0scist@0 199 while [ -e $NEWNAME ]
k0scist@0 200 do
k0scist@0 201 NEWNAME=${NEWNAME}.tmp
k0scist@0 202 echo "$NEWNAME"
k0scist@0 203 done
k0scist@0 204
k0scist@0 205 mv `basename $1` $NEWNAME
k0scist@0 206 mv `basename $2` `basename $1`
k0scist@0 207 mv $NEWNAME `basename $2`
k0scist@0 208 }
k0scist@0 209
k0scist@0 210 isrunning() {
jhammel@71 211 # is a process running? (by name)
k0scist@0 212 for i in "$@"
k0scist@0 213 do
k0scist@0 214 ps axwww | grep "$i" | grep -v 'grep'
k0scist@0 215 done | sort | uniq
k0scist@0 216
k0scist@0 217 }
k0scist@0 218
k0scist@0 219 killbyname() {
jhammel@71 220 # kill a process by name
k0scist@0 221 kill `isrunning "$@" | awk '{ print $1 }' | onelineit.py`
k0scist@0 222 }
k0scist@0 223
k0scist@0 224
k0scist@0 225 tf() {
k0scist@0 226 if [[ $@ ]]
k0scist@0 227 then
k0scist@0 228 echo "true"
k0scist@0 229 else
k0scist@0 230 echo "false"
k0scist@0 231 fi
k0scist@0 232 }
k0scist@0 233
k0scist@0 234 # full name
k0scist@0 235 fn() {
k0scist@0 236 python -c "import os; print os.path.realpath('$*')"
k0scist@0 237 }
k0scist@0 238
k0scist@0 239 # which view
k0scist@0 240 whview() {
k0scist@0 241 less `which $@`
k0scist@0 242 }
k0scist@0 243
jhammel@66 244 # which emacs
k0scist@0 245 whemacs() {
k0scist@0 246 emacs -nw `which $@`
k0scist@0 247 }
k0scist@0 248
k0scist@0 249 pyfile() {
jhammel@71 250 # python file name
k0scist@0 251 python -c "import $1; print $1.__file__"
k0scist@0 252 }
k0scist@0 253
k0scist@0 254 svndance(){
jhammel@71 255 # do the svn import dance!
k0scist@0 256 if (( $# ))
k0scist@0 257 then
k0scist@0 258 svn import $1
k0scist@0 259 cd ..
k0scist@0 260 rm -rf $OLDPWD
k0scist@0 261 svn co $1 $OLDPWD
k0scist@0 262 cd $OLDPWD
k0scist@0 263 else
k0scist@0 264 return 1
k0scist@0 265 fi
k0scist@0 266 }
k0scist@0 267
jhammel@71 268 difffiles() {
jhammel@71 269 grep '^+++ ' $@ | sed 's/+++ b\///'
jhammel@71 270 }
jhammel@71 271
jhammel@84 272 hg-update-all() {
jhammel@84 273 for i in *;
jhammel@84 274 do
jhammel@84 275 if [ -e $i/.hg ]
jhammel@84 276 then
jhammel@84 277 cd $i
jhammel@84 278 hg pull
jhammel@84 279 hg update
jhammel@84 280 cd -
jhammel@84 281 fi
jhammel@84 282 done
jhammel@84 283 }
jhammel@84 284
jhammel@110 285 hg-qcommit() {
jhammel@110 286 message=$1
jhammel@110 287 hg qrefresh
jhammel@110 288 if [ -z "${message}" ]
jhammel@110 289 then
jhammel@110 290 hg qcommit
jhammel@110 291 else
jhammel@110 292 hg qcommit -m "${message}"
jhammel@110 293 fi
jhammel@110 294 hgroot=$(hg root)
jhammel@110 295 patches=${hgroot}/.hg/patches/
jhammel@110 296 if [ -e ${patches}.hg ]
jhammel@110 297 then
jhammel@110 298 cd ${patches}
jhammel@110 299 hg push
jhammel@110 300 fi
jhammel@111 301 cd -
jhammel@110 302 }
jhammel@110 303
jhammel@90 304 blog-file() {
jhammel@90 305 echo "$HOME/web/blog/k0s/entries/public/$1"
jhammel@90 306 }
jhammel@90 307
jhammel@89 308 hgrc() {
jhammel@89 309 ROOT="${1}"
jhammel@89 310 echo "[paths]"
jhammel@89 311 echo "default = ${ROOT}"
jhammel@89 312 echo "default-push = ssh://${ROOT#http*://}"
jhammel@89 313 }
jhammel@89 314
jhammel@101 315 flatten() {
jhammel@101 316 directory=$PWD
jhammel@101 317 if [ "$#" == "1" ]
jhammel@101 318 then
jhammel@101 319 directory=$1
jhammel@101 320 fi
jhammel@101 321 cd $directory
jhammel@101 322 unset find # don't use the alias
jhammel@102 323 find . -name '*' -type f | sed 's/.\///' | while read line
jhammel@101 324 do
jhammel@101 325 filename=$(echo $line | sed 's/\//-/g')
jhammel@101 326 mv "${line}" "${filename}"
jhammel@101 327 done
jhammel@101 328 for i in *
jhammel@101 329 do
jhammel@101 330 if [ -d $i ]
jhammel@101 331 then
jhammel@101 332 rm -rf "${i}"
jhammel@101 333 fi
jhammel@101 334 done
jhammel@101 335 }
jhammel@101 336
jhammel@103 337 filehandles() {
jhammel@103 338 TMPFILE=$(tmpfile)
jhammel@103 339 ps -e|grep -v TTY|awk {'print "echo -n \"Process: "$4"\tPID: "$1"\tNumber of FH: \"; lsof -p "$1"|wc -l"'} > ${TMPFILE}
jhammel@103 340 . ${TMPFILE} | sort
jhammel@103 341 rm ${TMPFILE}
jhammel@103 342 }
jhammel@103 343
jhammel@167 344 quotemail() {
jhammel@167 345
jhammel@167 346 command='s/^/> /'
jhammel@167 347 inplace=""
jhammel@167 348 if [ "$#" == "2" ]
jhammel@167 349 then
jhammel@167 350 inplace="-i"
jhammel@167 351 fi
jhammel@167 352
jhammel@167 353 sed ${inplace} "${command}" "$1"
jhammel@167 354
jhammel@167 355 }
jhammel@167 356
k0scist@0 357 ### include overrides for commands
k0scist@0 358 source ~/.bash_overrides
k0scist@47 359
k0scist@47 360 ### regenerate fluxbox menus here for convenience
k0scist@47 361 MENU=~/web/site/programs.html
jhammel@237 362 regeneratefluxmenu() {
k0scist@47 363 if [ -e $MENU ]
k0scist@47 364 then
k0scist@47 365 html2flux.py $MENU > ~/.fluxbox/applications
jhammel@222 366 fi
jhammel@237 367 }
jhammel@237 368
jhammel@237 369 regeneratefluxmenu