### -*-sh-*- ### ### Description: .profile script for GNU Bash ### Author: Tudor Hulubei ### $Id: .profile,v 1.1 2005/05/09 17:04:03 tudor Exp $ ### # Make sure we are in the correct directory, even after a `su'. # FIXME: This has a weird effect on the shell, causing it to be unable # to execute scripts in certain situations. I don't really understand # what is going on, so I disabled it. #cd; # Export everything by default. We heavily rely on this! set -a; # Aliases cannot be exported. Get rid of them. unalias -a; # We count our own shell levels, SHLVL is not good enough because we # might be called for the first time when SHLVL is already > 1. if [ -z "$MYSHLVL" ]; then MYSHLVL=1; else MYSHLVL=`expr $MYSHLVL + 1`; fi # Check for Windows early, with the PATH provided by CYGWIN. OS="`uname -sr|awk '$1=="SunOS"&&$2>5{print"Solaris";exit};{print$1}'`"; if [ `echo "$OS" | cut -c1-6` = "CYGWIN" ]; then OS=Windows; fi if [ x"$OS" = x"Windows" ]; then # I don't know how to detect this automatically... # You'll have to set it manually for now. if [ "$HOME" ]; then USER=`basename $HOME`; else USER=tudor; HOME="/Windows/Profiles/$USER"; fi fi # This is exported at `su' with the wrong value. unset -v MAIL; unset -v MAIL_WARNING; # Set the hostname. if [ ! "$HOSTNAME" ]; then HOSTNAME="`hostname`"; fi HOST="$HOSTNAME"; # Configure the USER and LOGNAME variables. They should contain # the same value. # # There is no easy, portable way of doing this. bash provides only # the user id and we cannot look at the password database - it won't # work on systems that use NIS. And we want to reflect `su' changes # as well. Hopefully, each user's home directory will be named after # the user's login name. For `root' this might not be true, but we # know that root's UID is 0... if [ "$UID" -eq 0 ]; then USER="root"; else USER="`basename $PWD`"; fi LOGNAME="$USER"; # user: umask=022 (UPG), umask=077 (!UPG). # root: umask=022, for convenience. if [ x"$USER" = x"root" ]; then umask 022; else umask 077; if [ x"$OS" = x"Linux" ]; then if [ x"$USER" = x`id -gn` ]; then umask 007; fi fi fi # Create ~/.bashrc and ~/.Xresources, if missing. if [ ! -L ~/.bashrc ]; then rm ~/.bashrc 2> /dev/null; ln -s ~/.profile ~/.bashrc; fi if [ -f ~/.Xdefaults -a ! -L ~/.Xresources ]; then rm ~/.Xresources 2> /dev/null; ln -s ~/.Xdefaults ~/.Xresources; fi # Create the ~/tmp directory. mkdir ~/tmp 2>/dev/null; TMPDIR=~/tmp; # Some bash settings. rm -f ~/.bash_history 2> /dev/null; HISTFILE=~/.history; # History goes into ~/.history. FIGNORE='.o:.lo:.class:~'; # Ignore some files in file name completion. # Read the personal/site-dependent configuration file. if [ -f ~/.sitedep ]; then . ~/.sitedep; else echo "warning: \`~/.sitedep' file is missing"; fi if [ ! -f ~/.signature ]; then echo "warning: creating empty \`~/.signature' file"; > ~/.signature; fi # Unset the REPLYTO, NNTPSERVER and UUCPSERVER environment variables # if they have bogus values. if [ -z "$REPLYTO" ]; then unset -v REPLYTO; fi if [ -z "$NNTPSERVER" ]; then unset -v NNTPSERVER; fi if [ -z "$UUCPSERVER" ]; then unset -v UUCPSERVER; fi # dir in 'cd [dir]' is searched in these paths. CDPATH=".:~:~/src:"; # Set the PATH environment variable. Add here as needed. The system # provided PATH is ignored because we need to start from scratch every # time the shell is launched under a different user id. Doing # otherwise would propagate user specific path components (like # ~/bin) into the new user environment. If you feel that this is # not what you want, just add `:$PATH' at the end of the first line. # The system provided PATH is saved in SYSTEM_PATH. if [ ! "$SYSTEM_PATH" ]; then SYSTEM_PATH="$PATH"; fi # Use $HOME here, `/usr/bin/which' doesn't know how to expand `~'. PATH="$HOME/bin:$HOME/usr/bin:$HOME/usr/$OS/bin:$HOME/opt/bin:/usr/bsd"; PATH="$PATH:/opt/java/bin:/opt/bin:/usr/local/bin:/usr/gnu/bin:/bin:/usr/bin"; PATH="$PATH:/opt/gnu/bin:/sbin:/usr/sbin:/opt/sbin:/usr/vue/bin:/usr/games"; PATH="$PATH:/etc:/usr/etc:/usr/bin/X11:/usr/X11/bin:/usr/X11R6/bin"; PATH="$PATH:/usr/openwin/bin:/usr/dt/bin:/opt/X11R5/bin:/usr/X11R5/bin"; PATH="$PATH:/usr/TeX/bin:/usr/local/TeX/bin:/opt/TeX/bin:/usr/mpich/bin"; PATH="$PATH:/usr/java/bin:/usr/local/java/bin:/opt/kde/bin:/opt/gnome/bin"; PATH="$PATH:/usr/athena/bin"; # Under Windows we have to use the system provided PATH to make # sure we include that path to CYGWIN. if [ x"$OS" = x"Windows" ]; then PATH="$PATH:$SYSTEM_PATH"; fi # Set the MANPATH environment variable. Add here as needed. MANPATH="$MANPATH:/usr/local/man:/usr/share/man:/opt/gnu/man:/opt/TeX/man"; MANPATH="$MANPATH:/usr/dt/man:/usr/openwin/man:/opt/X11R5/man:/usr/athena/man"; case "$OS" in Linux) PATH="$PATH:/usr/lib/uucp:/usr/local/lib/uucp"; ;; SunOS | Solaris) PATH="$PATH:/opt/SUNWspro/bin"; PATH="$PATH:/usr/xpg4/bin:/usr/ucb:/usr/ccs/bin:/usr/contrib/bin"; MANPATH="$MANPATH:/opt/SUNWspro/man"; ;; esac # Add to PATH the site specific directories. PATH="$SITEPATH:$PATH"; # Set the CLASSPATH environment variable. Add here as needed. CLASSPATH="$SITECLASSPATH:/opt/java/lib:."; # We don't want to display the full host name on the xterm title... BASEHOSTNAME="`echo "$HOSTNAME" | cut -d. -f1`"; # Improve speed by avoiding the redefinition of those things that have # already been defined & exported (variables and functions). The only # notable exception are aliases, which cannot be exported and are # therefore not used at all. if [ $MYSHLVL -eq 1 ]; then . ~/.profile2; fi # The following functions are not in `.profile2' because the variables # storing the path to the executable might be affected by persona # changes. unset -f xemacs; __XEMACS="`type -path xemacs-mule`"; if [ $? -eq 0 -a "$DISPLAY" ]; then __HAVE_XEMACS=yes; else __XEMACS="`type -path xemacs`"; if [ $? -eq 0 ]; then __HAVE_XEMACS=yes; fi fi if [ x"$__HAVE_XEMACS" = x"yes" ]; then function xemacs() { gnuclient -q "$@" 2>/dev/null; if [ $? -ne 0 ]; then "$__XEMACS" "$@"; fi } fi unset __HAVE_XEMACS; unset -f emacs; __EMACS="`type -path emacs`"; if [ $? -eq 0 ]; then function emacs() { emacsclient --no-wait "$@" 2>/dev/null; if [ $? -ne 0 ]; then "$__EMACS" "$@"; fi } fi # Quit .profile if stdin is not a terminal. if [ ! -t 0 ]; then return 0; fi # ONLY `$TERM' RELATED STUFF BEYOND THIS POINT! # The cygwin terminal has colors, so we don't bother to check. # We don't have `tput' there anyway. if [ x"$OS" != x"Windows" ]; then # This will fail if the system has no termcap/terminfo description # for the terminal specified in $TERM. tput init >/dev/null 2>&1; if [ $? -ne 0 ]; then # Convert xterm-color, xterms, aixterm and dtterm to xterm. if [ x"$TERM" = x"xterm-color" -o\ x"$TERM" = x"xterm-debian" -o\ x"$TERM" = x"rxvt" -o\ x"$TERM" = x"xterms" -o\ x"$TERM" = x"aixterm" -o\ x"$TERM" = x"dtterm" ]; then TERM="xterm"; else # Convert iris-ansi and iris-ansi-net to ansi. if [ x"$TERM" = x"iris-ansi" -o\ x"$TERM" = x"iris-ansi-net" ]; then TERM="ansi"; fi fi tput init >/dev/null 2>&1; # If everything else fails, default to `vt100'. if [ $? -ne 0 ]; then TERM=vt100; fi fi fi if [ x"$TERM" = x"linux" -o\ x"$TERM" = x"aixterm" -o\ x"$TERM" = x"dtterm" -o\ x"$TERM" = x"iris-ansi" -o\ x"$TERM" = x"iris-ansi-net" -o\ x"$TERM" = x"xterm" -o\ x"$TERM" = x"xterms" -o\ x"$TERM" = x"xterm-debian" -o\ x"$TERM" = x"rxvt" -o\ x"$TERM" = x"xterm-color" -o\ x"$TERM" = x"cygwin" ]; then __TERM_HAS_COLORS=yes; else __TERM_HAS_COLORS=no; fi # Unset COLORTERM if we're not running on a xterm-like terminal emulator. if [ x"$__TERM_HAS_COLORS" = x"no" ]; then unset -v COLORTERM; fi # Use hpterm on HP-UX if running on /dev/console. Not portable. if [ x"$OS" = x"HP-UX" ]; then if [ "`tty`" = "/dev/console" ]; then TERM=hpterm; fi fi # If TERM is not set (or set to "dumb", etc.), force it to vt100. if [ x"$TERM" = x"dumb" -o\ x"$TERM" = x"DB" -o\ x"$TERM" = x"screen" -o\ x"$TERM" = x"network" ]; then TERM=vt100; fi # When using shell-mode under GNU Emacs there is no need for a pager. if [ x"$TERM" = x"emacs" ]; then function pager() { cat "$@"; } function less() { cat "$@"; } function more() { cat "$@"; } fi # Fancy ls. You still get colors under Linux, even when you use a pipe. # Make sure you use the regular ls (which is not modified by this file) # when you _really_ need to filter out the color codes in pipes. # # This works for Linux only, the -C & -p options are different for HP-UX, # Sun, etc. To be fixed. # # Overwrite LS_OPTIONS defined by Linux in /etc/profile. # BLACK/RED/GREEN/YELLOW/BLUE/MAGENTA/CYAN/WHITE: 0/../7 LS_COLORS="\ or=41:ln=34:bd=34:cd=35:pi=45;32:\ *.c=32:*.cc=32:*.cpp=32:*.h=32:*.java=32:*.l=32:*.y=32:*.s=32:\ *.m4=32:*.pl=32:*.el=32:*.lisp=32:*.in=32:\ *.o=34:*.a=34:*.so=34:*.lo=34:*.la=34:*.elc=34:*.class=34:\ *.ps=35:*.eps=35:*.fig=35:*.dvi=35:*.pdf=35:*.gif=35:*.jpg=35:*.jpeg=35:\ *.djv=35:*.tif=35:*.tiff=35:*.bmp=35:*.png=35:*.ppm=35:*.pgm=35:*.pbm=35:\ *.xpm=35:*.xpm=35:*.icon=35:*.ras=35:*.tga=35:*.mov=35:*.mpg=35:*.mpeg=35:\ *.avi=35:*.fli=35:*.flc=35:\ *.au=33:*.wav=33:*.mp3=33:*.ra=33:*.ram=33:*.mod=33:*.midi=33:*.voc=33:\ *.aiff=33:*.rmd=33:\ *.Z=31:*.bz2=31:*.gz=31:*.uu=31:*.shar=31:*.arj=31:*.zip=31:*.rar=31:\ *.jar=31:*.tar=31:*.tgz=31:*.taz=31:*.rpm=31:"; if [ x"$TERM" = x"linux" ]; then LS_COLORS="$LS_COLORS:di=36;1:so=45;33;1:ex=44;33;1:"; else LS_COLORS="$LS_COLORS:di=36:so=45;33:ex=44;33:"; fi if [ ! "$__LS" ]; then unset -f ls; __LS="`type -path ls`"; if [ $? -eq 0 ]; then function ls() { if [ x"$__TERM_HAS_COLORS" = x"yes" -a -t 1 ]; then if [ x"$OS" = x"Linux" -o x"$OS" = x"Windows" ]; then "$__LS" -CFp --color=yes "$@"; return $?; fi fi "$__LS" "$@"; } fi fi # System dependent terminal settings. # # In order to be able to use C-s with bash to perform # forward-search-history, add `stty stop "^-"' to undefine the stop # character (the default on my Linux box). # # Note: for some obscure reason, under Linux startx will not work # if we try to use stty in .profile, as we do here. We are taking # care of this in ~/.xsession. if [ x"$OS" != x"Windows" ]; then stty hupcl isig -ixon kill "^U" intr "^C" eof "^D"; case "$OS" in "Linux") stty stop "^-" erase "^?";; "HP-UX") stty erase "^H";; esac fi # Set the window title and icon strings, if TERM supports it. if [ x"$TERM" = x"xterm" -o\ x"$TERM" = x"xterm-color" -o\ x"$TERM" = x"xterm-debian" -o\ x"$TERM" = x"rxvt" -o\ x"$TERM" = x"xterms" -o\ x"$TERM" = x"dtterm" -o\ x"$TERM" = x"aixterm" -o\ x"$TERM" = x"iris-ansi" -o\ x"$TERM" = x"iris-ansi-net" -o\ x"$TERM" = x"cygwin" ]; then PROMPT_COMMAND='echo -ne "\033]1;$BASEHOSTNAME\007\033]2;$OS Shell"'; PROMPT_COMMAND="$PROMPT_COMMAND"'" - $USER@$BASEHOSTNAME : $PWD\007"'; else unset -v PROMPT_COMMAND; fi # __USER, __HOST & __PATH can be defined in .sitedep, if colors are # supported. Suggested by Andrei Pitis . if [ x"$__TERM_HAS_COLORS" = x"yes" ]; then if [ ! $__USER ]; then __USER="\[\033[31m\]"; fi if [ ! $__HOST ]; then __HOST="\[\033[32m\]"; fi if [ ! $__PATH ]; then __PATH="\[\033[36m\]"; fi __DFLT="\[\033[0m\]"; else __USER=""; __HOST=""; __PATH=""; __DFLT=""; fi # Don't use \u instead of $USER here, bash under CYGWIN will get confused. PS1="$__DFLT[$__USER$USER$__DFLT@$__HOST\h$__DFLT]:$__PATH\w$__DFLT "'\$ '; # Linux >= 2.2.x supports fancy text mode cursors. if [ x"$OS" = x"Linux" -a x"$TERM" = x"linux" ]; then __RELEASE=`uname -r`; if [ `echo $__RELEASE | cut -d. -f1` -ge 2 -a\ `echo $__RELEASE | cut -d. -f1` -ge 2 ]; then echo -ne '\033[?64c'; fi unset __RELEASE; fi rm -f ~/core >/dev/null 2>&1;