## -*- shell-script -*-
## .shellrc -- global shell configuration file
## Copyright 2004-2008 by Michal Nazarewicz (mina86/AT/mina86.com)
## $Id: shellrc,v 1.13 2008/07/29 07:38:01 mina86 Exp $
##
# Not interactive?
[ X"${-#*i}" != X"$-" ] || return
# Hostname
if [ -z "$HOST" ]; then
HOST="$(hostname)"
HOST="${HOST%%.*}"
fi
_hostname=X"$HOST"
##
## If normal user -> umask 077; if super user -> umask 022
## Also, set TMOUT when super user and not running on pikus
##
if [ $(id -u) -eq 0 ] && [ "$_hostname" != Xpikus ]; then
umask 0022
TMOUT=1200
else
umask 0077
fi
##
## Some basic variables
##
[ -n "$UID" ] || UID="$(id -u)"
if [ -z "$USER" ]; then
if [ -n "$LOGNAME" ]
then USER="$LOGNAME"
else USER="$(id -un)"
fi
fi
[ -n "$LOGNAME" ] || LOGNAME="$USER"
[ -n "$HOME" ] || HOME="$(eval echo ~"$USER")"
##
## Prompt
##
# Default prompt (most likely will be overwritten in shell specific rc files)
if [ X"$UID" = X0 ]; then PS1='# '; else export PS1='$ '; fi
if [ -n "$SSH_CLIENT$SSH_CONNECTION" ]; then PS1="[$(hostname)]$PS1"; fi
export PS1
# Add title to terminals
case "$TERM" in xterm*|rxvt*)
printf '\033]2;%s@%s\07' "$USER" "$HOST"
esac
##
## Aliases & functions
##
# ls
unalias ls dir vdir ll l 2>/dev/null
alias ls='LANG=C ls $LS_OPTIONS'
alias ll='ls -l'
## make and change directory
unalias md 2>/dev/null
md () {
if [ $# -eq 0 ]; then
echo usage: 'md dir [ dir ... ]' >&2
return 1
else
mkdir -p -- "$@" && cd "$1"
fi
}
## List directory or content of file
l () {
if [ $# -eq 1 -a -f "$1" ]; then
less -- "$1"
elif [ $# -eq 2 -a x"$1" = x-- -a -f "$2" ]; then
less -- "$2"
else
ls "$@"
fi
}
# Other
if which run-emacs >/dev/null 2>&1; then
alias e=run-emacs
elif which emacsclient >/dev/null 2>&1; then
alias e='emacsclient -n'
fi
alias rmd=rmdir
which mpc >/dev/null 2>&1 && alias mpc="mpc --format '[[[%artist% <&%album%> ]|[%artist% - ]|[<%album%> ]]%title%]|[%file%]'"
if which git >/dev/null 2>&1; then
alias g=git
alias -- '+=git add'
fi
# Perl stuff
unalias pf pd 2>/dev/null
pf () {
if [ $# -eq 0 ]; then perldoc perlfunc; else perldoc -f "$@"; fi
}
pd () {
case "$1" in
perl*|*::*|-*|*[A-Z]*)
perldoc "$@"
;;
*)
perldoc "perl$1"
esac
}
# tinyapps stuff
if ! which xrun >/dev/null 2>&1; then
xrun () { "$@" & }
fi
if which cdiff >/dev/null 2>&1; then
alias diff=cdiff
fi
# More colors
if echo foo | grep --color=auto foo >/dev/null 2>/dev/null; then
alias grep='grep --color=auto'
alias fgrep='grep -F'
alias egrep='grep -E'
fi
##
## Variables
##
# For setting flags
if [ -e ~/bin/flags-do ]; then
unalias flags 2>/dev/null
flags () {
. ~/bin/flags-do "$@"
}
fi
# No need to set it once again
if [ -n "$MINA86RC" ]; then
unset _hostname
return
fi
export MINA86RC=done
# PATH
if ! echo "$PATH" | grep -F "$HOME/bin" -F '~/bin' >/dev/null 2>&1; then
if [ -d ~/code/tinyapps ]; then PATH="$HOME/code/tinyapps:$PATH"; fi
if [ -d ~/bin ]; then PATH="$HOME/bin:$PATH"; fi
if [ -d ~/bin64 ] && [ x"`uname -m`" = xx86_64 ]; then
PATH="$HOME/bin64:$PATH"
fi
fi
# Remove relative paths
PATH="$(echo ":$PATH:" | sed -e 's~:\(\([^/:][^:]*\)\?:\)*~:~g
s/^::*//
s/::*$//')"
export PATH
# Editor
[ -z "$EDITOR" ] && which nano >/dev/null 2>&1 && export EDITOR=nano VISUAL=nano
# less
if [ -n "$LESS" ] || which less >/dev/null 2>&1; then
export PAGER=less LESS=-MS
[ -x ~/bin/lesspipe ] && eval $(~/bin/lesspipe --install-lesspipe)
fi
# LaTeX
TEX=`which platex 2>/dev/null`
[ -n "$TEX" ] || TEX=`which latex 2>/dev/null`
[ -n "$TEX" ] || TEX=`which tex 2>/dev/null`
if [ -z "$TEX" ]; then
unset TEX
else
export TEX
fi
# LS options and colors
if [ -z "$LS_COLORS" ] && ls --color / >/dev/null 2>&1; then
if which dircolors >/dev/null 2>&1; then
if [ -f ~/.dir_colors ]; then eval "`dircolors -b ~/.dir_colors`"
elif [ -f /etc/DIR_COLORS ]; then eval "`dircolors -b /etc/DIR_COLORS`"
else eval "`dircolors -b`"
fi
elif [ -x ~/bin/dircolors ]; then
. ~/bin/dircolors
fi
fi
LS_OPTIONS="-FT0 --color=auto"
export LS_OPTIONS
# Various
export GZIP="-9n"
export FIGNORE=".o:~:.bak" CC=gcc CXX=g++
export LC_COLLATE=C LC_MESSAGES=en_GB
case "$_hostname" in (Xerwin|Xtuptus)
unset MAILCHECK MAIL
if [ x"`uname -m`" = xx86_64 ]; then
export ARCH=x86_64
else
export ARCH=i686
fi
flags init
esac
unset _hostname