# -*- shell-script -*-
#
# Joerg Arndt's  .profile
# ... online at http://www.jjj.de/
# your feedback is welcome  mailto: arndt (AT) jjj.de
#
# version: 2023-November-02 (14:05)
#
# You may want to make your .zshrc and .bashrc a link to this file:
# ln -sv .profile .zshrc
# ln -sv .profile .bashrc
#

# The following gives other users a way to check
#   if they like this configuration:
# JJHOME=~jj  . ~jj/.profile
if [ -z "$JJHOME" ]; then  JJHOME=$HOME;  fi


if [ -t 0 ]; then # echo only if on tty
#    if [ -z "$JJ_CONFIG_READ" ]; then
#        echo '~/.profile ...';
#        echo -n '-';
#    else
#        echo '~/.profile .....';
#        echo -n '+';
#    fi

    if [ "$JJHOME" != "$HOME" ]; then
        echo  "  using JJHOME=$JJHOME";
    fi
fi


### cf. http://zshwiki.org/home/zen
## FAILS
#fpath=(
#        $fpath
#        /home/jj/.zen/zsh/scripts
#        /home/jj/.zen/zsh/zle )
#autoload -U zen
##INF: Example:
##% zen search
##% zen install zsh/scripts/zpaste


export EMACS_TOOLKIT="x11"


export XEDITOR="/usr/bin/emacs -no-site-file"
export EDITOR="/usr/bin/emacs -no-site-file"
export VISUAL="/usr/bin/emacs -no-site-file"
export TEXEDIT="/usr/bin/emacs -no-site-file +%d %s"
export MPEDIT="/usr/bin/emacs -no-site-file +%d %s"

## colorful GGC warnings and erorrs with recent versions:
export GCC_COLORS="error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01"


#if [ "$TERM" = "dumb" ]; then  unset DISPLAY;  fi

# need some method to determine whether terminal can display colors:
#if [ "$TERM" != "dumb" ]; then
# dir-colors settings:
if [ -x /usr/bin/dircolors ] ; then
    if [ -r $JJHOME/.jjdircolors ] ; then
        eval $(dircolors -b $JJHOME/.jjdircolors);
    else
        echo "no file $JJHOME/.jjdircolors ?"
    fi;
else
    echo "no executable /usr/bin/dircolors ?"
fi

# define "color-variables":
if test -f $JJHOME/.jjtermcolors; then
    . $JJHOME/.jjtermcolors
# ... these are unset near the end of this file
else
    echo "no file $JJHOME/.jjtermcolors ?";
fi

# we are in an xterm and DISPLAY is not set:
# probably a root xterm was opened, so we set DISPLAY
if [ "$TERM" = "xterm" -a -z "$DISPLAY" ]; then
    export DISPLAY=:0.0
fi
#
#
#if [ "$TERM" != "linux" ]; then
#    export TERM=xterm-256color
#    ## in emacs-now try  M-x list-colors-display
#fi



#export MAIL=/var/mail/$LOGNAME
export MAIL=$HOME/mail/.incoming
#unset MAIL
unset MAILPATH
unset MAILCHECK

## format for /usr/bin/time:
#export TIME='%U user  %S system  %E elapsed  %P CPU'
#export TIME='%U user  %S system  %E elapsed'
##  The default format is:
##         %Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k
##         %Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps
unset TIME
alias time='/usr/bin/time'

# A colon-separated list of suffixes to ignore when performing
# filename completion A file name whose suffix matches one of the
# entries in `FIGNORE' is excluded from the list of matched file
# names.  A sample value is `.o:~'
FIGNORE=".o:~"

# The number of commands to remember in the command history
# The default value is 500.
export HISTSIZE=10000
export HISTFILESIZE=${HISTSIZE}

# The  name  of  the file in which command history is
# saved.  The  default  value  is ~/.bash_history or ~/.zsh_history.
# If unset, the command history is not saved when an
# interactive shell exits.
#unset HISTFILE


# if home dir contains a link make dirs show it as ~ anyway:
export HOME=$(cd; pwd;)

# logout (only) after typing ignoreeof plus one ctrl-d:
export ignoreeof=1

# max core file size:
ulimit -c 0



#if [ -z "$JJ_CONFIG_READ" ]; then # stuff to do once only

    if [ "$EUID" = "0" ]; then  # for root:
        PATH="/usr/local/bin:/usr/local/sbin:$PATH";
    else # for non-root:
        PATH="/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:$PATH";
    fi

    if [ -d ~/.cargo/bin ]; then
        PATH="~/.cargo/bin:$PATH";
    fi
    if [ -d ~/bin ]; then
        PATH="${HOME}/bin:$PATH";
    fi

#    PATH=$PATH:./ ## adding local dir is a security problem

    export PATH
#fi



. $JJHOME/.alias

if test -n "$BASH_VERSION"; then # ------- BASH ONLY
    . $JJHOME/.jjbashrc
fi # ------- end BASH ONLY


if test -n "$ZSH_VERSION"; then # ------- ZSH ONLY
    source $JJHOME/.jjzshrc
fi # ------- end ZSH ONLY


# unset color stuff: (else 'set' and 'env' produce rather colorful output)
test -f $JJHOME/.jjtermcolors  &&  . $JJHOME/.jjtermcolors unset ;
#

# ... and
# keep in mind we've seen this file:
export JJ_CONFIG_READ=1

## is my favorite Window-Manager available?
ctwm -version &>/dev/null  &&  export WINDOWMANAGER=ctwm

export DICTIONARY=american

export PAGER=less
#export LESSCHARSET=latin1
export LESS=-iM

if test $(whoami) = 'root'; then
    export LC_ALL=C
else
    #unset LC_ALL
    export LC_ALL=en_US.UTF-8
    export LANG=${LC_ALL}
    export LANGUAGE=${LC_ALL}
    #
    export LC_PAPER=en_GB.UTF-8    # <--- A4 paper
    export LC_MESSAGES=en_US.UTF-8 # <--- english messages
    export LC_COLLATE=C            # <--- sorting order
    #export LC_COLLATE=en_US.UTF-8  # <--- sorting order
    export LC_CTYPE=en_US.UTF-8    # <--- encoding, fonts, UTF-8 mode for xterm etc.
fi

##export TEXDOCVIEW_dvi='xdvi %s'
#export TEXDOCVIEW_ps='gv %s'
#export TEXDOCVIEW_pdf='gv %s'
#export TEXDOCVIEW_html='links -g %s'


#export MALLOC_CHECK_=0


# local stuff (e.g. export DISPLAY=0:0)
# may override some variables, therefore moved to end
test -f ~/.jjlocal  &&  source ~/.jjlocal
# HN == hostname without trailing dot
#HN=${HOSTNAME/./}
HN=$(hostname)
test -f ~/.jjlocal-${HN}  &&  source ~/.jjlocal-${HN}

#if type dnsdomainname >/dev/null ; then
#    DN=$(dnsdomainname);
if type hostname >/dev/null ; then
    DN=$(hostname);
    ## ccache etc.:
    test -f ~/.jjlocal-$DN  && source  ~/.jjlocal-$DN ;
else
    :  # do not return error
fi

## silence yet another Gnome fuckup, see
##   http://computing.help.inf.ed.ac.uk/accessibility-bus
export NO_AT_BRIDGE=1


# rustup shell setup:
. "$HOME/.cargo/env"

#export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"

#### end of file ####
