#!/bin/sh

export XDG_CONFIG_HOME="$HOME"/.config
[ -d "$XDG_CONFIG_HOME" ] || mkdir -pv "$XDG_CONFIG_HOME"

export XDG_CACHE_HOME="$HOME"/.local/cache
[ -d "$XDG_CACHE_HOME" ] || mkdir -pv "$XDG_CACHE_HOME"

export XDG_DATA_HOME="$HOME"/.local/share
[ -d "$XDG_DATA_HOME" ] || mkdir -pv "$XDG_DATA_HOME"

export XDG_STATE_HOME="$HOME"/.local/state
[ -d "$XDG_STATE_HOME" ] || mkdir -pv "$XDG_STATE_HOME"

export XDG_BIN_HOME="$HOME"/.local/bin
[ -d "$XDG_BIN_HOME" ] || mkdir -pv "$XDG_BIN_HOME"

export PATH="$XDG_BIN_HOME":"$PATH"

# XDG_CONFIG_HOME
export PARALLEL_HOME="$XDG_CONFIG_HOME"/parallel
export XSERVERRC="$XDG_CONFIG_HOME"/X11/xserverrc
export XINITRC="$XDG_CONFIG_HOME"/X11/xinitrc
export _JAVA_OPTIONS=-Djava.util.prefs.userRoot="${XDG_CONFIG_HOME}/java"
export ENV="$XDG_CONFIG_HOME"/shell_cfg.sh

# XDG_DATA_HOME
export PASSWORD_STORE_DIR="$XDG_DATA_HOME"/pass
export GNUPGHOME="$XDG_DATA_HOME"/gnupg
export WINEPREFIX="$XDG_DATA_HOME"/wine
export ANDROID_HOME="$XDG_DATA_HOME"/android
export GRADLE_USER_HOME="$XDG_DATA_HOME"/gradle
export PSQL_HISTORY="$XDG_DATA_HOME"/psql_history
export JULIA_DEPOT_PATH="$XDG_DATA_HOME"/julia:"$JULIA_DEPOT_PATH"
export PYENV_ROOT="$XDG_DATA_HOME"/pyenv

# XDG_STATE_HOME
export LESSHISTFILE="$XDG_STATE_HOME"/less/history
[ -d "$XDG_STATE_HOME"/less ] || mkdir -pv "$XDG_STATE_HOME"/less

export SQLITE_HISTORY="$XDG_STATE_HOME"/sqlite/history
[ -d "$XDG_STATE_HOME"/sqlite ] || mkdir -pv "$XDG_STATE_HOME"/sqlite

export MYSQL_HISTFILE="$XDG_STATE_HOME"/mysql/history
[ -d "$XDG_STATE_HOME"/mysql ] || mkdir -pv "$XDG_STATE_HOME"/mysql

export HISTFILE="$XDG_STATE_HOME"/bash/history
[ -d "$XDG_STATE_HOME"/bash ] || mkdir -pv "$XDG_STATE_HOME"/bash

if [ -z "$XDG_RUNTIME_DIR" ]
then
	export XDG_RUNTIME_DIR="/run/user/$(id -u)"
	mkdir -pv "$XDG_RUNTIME_DIR"
fi


# XDG_RUNTIME_DIR
export XAUTHORITY="$XDG_RUNTIME_DIR"/Xauthority
export RXVT_SOCKET="$XDG_RUNTIME_DIR"/urxvtd

export HISTCONTROL=ignorespace
export HISTSIZE=-1
export HISTFILESIZE=-1

if [ -e "/usr/bin/ssh-agent" ]
then
    pgrep ssh-agent >/dev/null || eval "$(/usr/bin/ssh-agent)"
fi
