# vi settings: set show-match auto-indent always-redraw shift-width=4
#export EXINIT="se sm ai redraw sw=4"

# Configure the shell to load .shrc at startup time.
# This will happen for every shell started, not just login shells.
export ENV=$HOME/.shrc

# --- login routines ---

# create a user-owned  dir where
# to store temporary files
dir=/tmp/$(id -u)
if [ ! -d "$dir" ]; then
    mkdir -p $dir
    /sbin/chown -R $(whoami):$(id -gn) $dir
    chmod -R 0700 $dir
fi
export XDG_RUNTIME_DIR=${dir}
export TMPDIR=${XDG_RUNTIME_DIR}
unset dir

# Create a directory owned by the user under /tmp,
# and make ~/.cache a symbolic link to it.
#
CACHE="${HOME}/.cache"
[ -z $CACHE ] || rm -rf $(readlink $CACHE)
dir=$(mktemp -d /tmp/${LOGNAME}.XXXXXX)
ln -sf ${dir} $CACHE
unset dir


## test for an existing bus daemon, just to be safe
if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
  ## if not found, launch a new one
  eval `dbus-launch --sh-syntax`
  echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
  echo ''
fi

# mailbox notifications
if [ -x /usr/bin/biff ]; then
  biff y 2> /dev/null
  echo ''
fi

# give a fortune cookie
[ -x /usr/games/fortune ] && /usr/games/fortune -aes
echo ''

# display current date
echo ''; echo -n 'To days date is: '; date

# start ssh agent
if [ -x /usr/pkg/bin/keychain ]; then
  keychain id_ed25519
  . ${HOME}/.keychain/$(hostname)-sh
  echo ''
fi

# lauch tmux by default
if command -v tmux &> /dev/null && [ -z "$TMUX" ]; then
  tmux attach -t default || tmux new -s default
fi

