# ~/.bashrc
# Dr. David M. MacMillan. Copyright 2014.  GNU GPL 3+

# Are we an interactive shell?
##############################
#
# We only want to do the things in this .bashrc file if the bash shell
# is being invoked for interactive use.  We can detect whether this is the
# case by examining the bash special parameter '-', which contains the
# invocation flags.  If $- contains 'i', then we are interactive.
# This next line is a very compressed form of the bash "test"/if command
# which checks for this and quits (returns) if we are not interactive
# (it's from the default bash .bashrc).
[[ $- != *i* ]] && return


# Set the Prompt and xterm Titlebar
###################################
# 
# Adapted from
# http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/xterm-title-bar-manipulations.html
#
# The TITLEBAR shell variable contains an escape sequence which will
# display text in an xterm's title bar.  But it needs to be a part of
# the prompt string (PS) in order actually to be used.
# My own preference for the rest of the prompt string is very minimalist:
# use a single dash ("- ").
# 
# The console and xterms are handled differently.  If you use escape
# sequences to set the prompt, but are at the console, then you'll get
# garbage in the prompt.  So test to see if we're in an xterm and only
# set the prompt then.
#
# We must do this within a function, not inline, because "local" can be
# used only within a function.

function PromptAndTitleLine
{
case $TERM in
   xterm)
      #local TITLEBAR='\[\033]0;\u@\h:\w\007\]'  # user@host:workingdir
      local TITLEBAR='\[\033]0;\w\007\]'         # workingdir
      ;;
   *)
      local TITLEBAR=''
      ;;
esac
PS1="${TITLEBAR}- "
}
PromptAndTitleLine

# Old settings for PS, no longer used
#PS1='[\u@\h \W]\$ '      # from the default bash .bashrc file
#PS1='- '                 # my minimalist setting, without xterm TITLEBAR


# Aliases to (partly) configure certain commands
################################################

# ls (color, sorting order)
#--------------------------
# As normally shipped, the "ls" command is configured with three flaws.
# 1. color (get rid of it)
#    The default bash .bashrc for most systems now sets
#    alias ls='ls --color=auto'
#    This is exceedingly annoying.
#    To set the color off, do:
#    alias ls='ls --color=never'
# 2. trailing slashes (add them)
#    Although I tend to prefer a very minimalist configuration of ls,
#    I do like it to add a trailing '/' character to its output to
#    indicate a directory.  To do this:
#    alias ls='ls -F'
# 3. sorting order (correct it)
#    Modern Linux systems have a number of "locale" settings to 
#    adapt the machine to local preferences.  Generally this is good.
#    But the locale for "en_US.UTF-8" sets the sorting order to a
#    strange attempt at a "natural" or mostly-alphabetical order.
#    This is, I presume, intended as a convenience for those who
#    do not understand computers.  As I am fortunate in not suffering
#    from this disability, I wish to sort in the actual ASCII sorting
#    order which is *really* natural for the files.  This is done by
#    setting the "LC_COLLATE" environment variable to a null value,
#    or "POSIX", or "C".  One could do this in general for the entire
#    bash session by:
#    LC_COLLATE="C"; export LC_COLLATE
#    or individually just for the ls command by:
#    alias ls='LC_COLLATE="C" ls'
# There is a good discussion of the sorting order issue by Paul Heinlein at:
# http://www.madboa.com/geek/utf8/
#
# So all together, I have:
alias ls='LC_COLLATE="C" ls --color=never -F'

# vim
#----
alias vi='vim'

# garbage stdout/stderr
#----------------------
# Developers increasingly don't actually know how to program, so it's
# now common for some applications to spew error messages (most of which
# simply document mistakes in their use of their own tools) to stdout.
# These can be caught and redirected to the bitbucket.  (But some
# spew error messages to stdout (which is itself an error); it's harder
# to do anything about these while still keeping the functionality of stdout.
alias gimp='gimp 2> /dev/null'
alias vlc='vlc 2> /dev/null'
alias okular='okular > /dev/null 2> /dev/null'

# ENVIRONMENT (except PATHs)
############################
# Make sure that it's someplace with sufficient free space.
MAGICK_TMPDIR=$HOME/.magick_tmpdir;export MAGICK_TMPDIR


# PATHs
#######
# My own convention is to have a $HOME/bin directory for some of my *very*
# local executables. Comment this out if you have no such directory.

PATH=$PATH:$HOME/bin;export PATH

# add more PATHs below:


