# ~/.bashrc: executed by bash(1) for non-login shells. -*-sh-*-

# set -x

# Do not set PATH here! It is set in .profile
# . ~/dot/path

# Source Nix config if present.
NIX_SH=~/.nix-profile/etc/profile.d/nix.sh
[ -f $NIX_SH ] && {
    . $NIX_SH
    export PYTHONPATH=~/.local/lib/python3.7/site-packages
}


LOCALRC=~/dot/bashrc.`hostname -s`

# shopt -s histappend  # Don't ever delete history
# export PROMPT_COMMAND="history -n; history -a"   # Read/write history at every new prompt.

if [ -f "$LOCALRC" ]; then
    # echo sourcing $LOCALRC
    source $LOCALRC
fi

# If running interactively..
if [ "$PS1" ]; then

    if [ "$TERM" == dumb ]; then
        export COLUMNS=80
    fi

	## xmodmap no effect in ~/.xinitrc? (Was: hack Xorg 7.3 bug)
	if [ "$DISPLAY" == :0.0 ]; then
		# ~/bin/Xmodmap.sh >/dev/null
		# xrdb ~/.Xdefaults
		# xmodmap ~/dot/Xmodmap.ctrl
            echo -n
	fi 

    if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
        debian_chroot=$(cat /etc/debian_chroot)
    fi
	
    export PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    
    . ~/.alias
    
    # probably means we're in emacs. the $EMACS var doesnt get exported over ssh.
    if [ "$TERM" == dumb ]; then
	. ~/.emacs_alias
    else
	[ -f /etc/bash_completion ] && echo -n #/etc/bash_completion
    fi

    # screen hacks
    if  [ $TERM == "screen" ]; then
	PS1="($STY:$WINDOW) $PS1"
    fi

    # motd
    cat ~/.motd
fi

# export variables
export PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export LC_CTYPE=en_US.UTF-8
export CLASSPATH=.:$CLASSPATH

# To make java apps work correctly under Xmonad (avoid grey blobs).
export _JAVA_AWT_WM_NONREPARENTING=1

umask 022


# Git branch info
# Use ControlMaster .ssh/config otherwise this is too painful.
parse_git_branch() {
    BRANCH=$(smart-remote git name-rev --name-only HEAD 2>/dev/null)
    [ -z "$BRANCH" ] || echo "[$BRANCH] "
}
announce() {
    cat <<EOF | netcat -q0 localhost 12345 2>/dev/null&
EXO_TYPE=prompt
PWD=$(pwd)
EOF
}
annotate_dir() {
    H=$(storage-host)
    if [ $H != localhost ]; then
        echo -n "[$H] "
    fi
    #parse_git_branch
}

PS1_DEFAULT=$PS1
#PS1="\$(announce)\$(annotate_dir)$PS1_DEFAULT"
#PS1="\$(annotate_dir)$PS1_DEFAULT"
PS1="$PS1_DEFAULT"

# Do these in terminal?

#PS1="\$(parse_git_branch)$PS1"

EDITOR=emacsclient
export EDITOR

if [ -z "$LD_LIBRARY_PATH" ]; then
    export LD_LIBRARY_PATH=/home/tom/lib
else
    export LD_LIBRARY_PATH="/home/tom/lib:$LD_LIBRARY_PATH"
fi



# [ -z "$SSH_AUTH_SOCK" ] && SSH_AUTH_SOCK=/tmp/ssh-agent.tom
(ssh-add -l >/dev/null 2>&1) || SSH_AUTH_SOCK=$(~/bin/find-agent.sh)
export SSH_AUTH_SOCK


# It seeems easiest to define this globally.
export HATD_SSH_PROXY=tom@10.1.1.193

