#
# Custom profile for {RedHat,Fedora,OpenSuSE,Ubuntu} Linux systems
# Copyright 2001,2002,2004,2007,2008,2009 Bernie Innocenti <bernie@codewiz.org>
#
# Manual fixes required for Ubuntu/Debian:
#   Use /bin/bash in /etc/gdm/Xsession
#   Remove PS1 messups in /etc/bash.bashrc
#

# Set defaults, then read config(s) in override order
HOST_COLOR='\033[37m'
HOST_CFLAGS='-march=native'
HOST_CORES=2
[ -r /etc/profile.conf     ] && source /etc/profile.conf # OBSOLETE
[ -r /etc/zzz_profile.conf ] && source /etc/zzz_profile.conf
[ -r ~/.zzz_profile.conf   ] && source ~/.zzz_profile.conf

# wants tty to be owned by tty
[ -w "`tty`" ] && mesg y

CFLAGS="$HOST_CFLAGS -O2 -ffast-math -fomit-frame-pointer -DNDEBUG -pipe"
CXXFLAGS="$CFLAGS -fno-enforce-eh-specs"
EDITOR=vim
LESS='--ignore-case --hilite-search --RAW-CONTROL-CHARS --chop-long-lines'
export CFLAGS CXXFLAGS EDITOR LESS

# reorder local
PATH=/usr/local/bin:`echo $PATH | sed -e 's,:*/usr/local/bin,,g'`

# Add /sbin to users too (only Fedora 10 does it)
case $PATH in
	*/sbin/*) ;;
	*) PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH ;;
esac

# reorder local in front of others
PATH=/usr/local/bin:`echo $PATH | sed -e 's,:*/usr/local/bin,,g'`

# Personal bin/ directory
[ -x $HOME/bin ] && PATH=$HOME/bin:$PATH

export PATH

MAILDIR=/mail/$LOGNAME
unset MAIL
export MAILDIR MAIL

#
# shell prompt goodness
#
if [ -n "$BASH_VERSION" ] ; then
	PS1='\['$HOST_COLOR'\]\h\[\033[0;36m\]:\[\033[32m\]\w\[\033[36m\]`[ -n "\`jobs\`" ] && echo [\`jobs -r | wc -l | xargs\`/\`jobs -s | wc -l | xargs\`]`\$\[\033[0m\] '
	[ "$UID" != 0 ] && PS1='\[\033[31m\]\u\[\033[36m\]@'"$PS1"
	[ -n "$CHROOT" ] && PS1='\[\033[32m\]'"$CHROOT"'\[\033[36m\]%'"$PS1"
	PS1='`_rc=$?; [ $_rc -ne 0 ] && echo "\[\033[1;31m\]$_rc!\[\033[0m\]"`'"$PS1"
	ignoreeof=0
	export PS1 ignoreeof
fi

sw() { mv $1 $1.$$ && mv $2 $1 && mv $1.$$ $2; }
rvim() { gvim --remote-silent "$@"; }
grep() { /bin/grep --color=auto "$@"; }
g() { grep -E "$@"; }
grepi() { grep -Eri "$@"; }
sgrep() { grep -ErnI --exclude-dir='.svn' --exclude-dir='.git' --exclude-dir='CVS' --exclude-dir '.hg' --exclude 'tags' --exclude-dir '.deps' --exclude-dir '.libs' --exclude '*.lst' --exclude '*.o' --exclude '*.d' "$@"; }
sfind() { find "$@" \( -name .svn -prune -o -name .git -prune -o -name .hg -prune -o -name CVS -prune -o -type f -not -name '*.o' \) -print; }
rpmqa() { rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort; }
please() { nice ionice -c2 -n6 "$@"; }
talk() { ytalk "$@"; }
bc() { /usr/bin/bc -l "$@"; }
memo() { ${EDITOR:-vim} ~/memo "$@"; }
gmemo() { gvim ~/memo "$@"; }

# don't use "export -f" on sh or bash emulating historical sh 
export_f=export
[ -n "$BASH_VERSION" ] && export_f='export -f'
$export_f sw rvim grep g grepi sgrep sfind rpmqa please talk bc memo gmemo

ZZZ_PROFILE_SH=1
export ZZZ_PROFILE_SH

