# /etc/profile: System-wide .profile file for the Bourne shells

PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/sbin:/usr/local/bin"
LD_LIBRARY_PATH="/usr/lib:/lib:/usr/local/lib"

# Prompt format for Ash (Bash use /etc/bashrc).
if [ $(id -u) -eq 0 ]; then
	# Red and blue for root
	PS1="\[\e[1;31m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\\$ "
	#PS1='\u@\h:\w\$ '
else
	# Green and blue for users
	PS1="\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\\$ "
	#PS1='\u@\h:\w\$ '
fi

# Max 64M for programs (prevent memory leak crashes)
#
# ulimit -d 65536	# commented out because lzma requires at least 94 MB of RAM to compress files.
ulimit -m 65536

# Screen display for X and encoding for GTK+ apps
#
[ -n "$DISPLAY" ] || DISPLAY=:0.0
G_FILENAME_ENCODING=UTF-8

# Make OpenOffice look better
#
OOO_FORCE_DESKTOP=gnome

# Export all variables defined above and set mask
#
export PATH LD_LIBRARY_PATH PS1 DISPLAY G_FILENAME_ENCODING
export OOO_FORCE_DESKTOP ignoreeof
umask 022

# Locale and timezone settings
#
if [ -s "/etc/locale.conf" ]; then
	. /etc/locale.conf
	export LANG LC_ALL
fi
if [ -s "/etc/TZ" ]; then
	TZ=$(cat /etc/TZ)
	export TZ
fi

# Update X Terminal window title
#
ip=$(ifconfig $(route -n 2>/dev/null | sed '/^0\.0\.0\.0/!d;s/.* //') 2>/dev/null | sed '/t a/!d;s/.*r:\([^ ]*\).*/\1/')
case "$TERM" in
	xterm*|rxvt*) echo -ne "\033]0;$(hostname) $(cat /etc/slitaz-release) $ip \007";;
esac


# User preferred applications

[ -z "$XDG_CONFIG_HOME" ] && export XDG_CONFIG_HOME="$HOME/.config"
if [ -s "$XDG_CONFIG_HOME/slitaz/applications.conf" ]; then
	. "$XDG_CONFIG_HOME/slitaz/applications.conf"
elif [ -s '/etc/slitaz/applications.conf' ]; then
	. '/etc/slitaz/applications.conf'
fi
export FILE_MANAGER BROWSER EDITOR TERMINAL WINDOW_MANAGER


# Bash compatibility

dirs() {
	echo $_dirs
}

pushd() {
	cd $1 && _dirs="$1 $_dirs" && dirs
}

popd() {
	[ -n "$_dirs" ] && _dirs="${_dirs#* }" && cd ${_dirs%% *} && dirs
}

command_not_found_handle() {
	[ -x /bin/command_not_found ] && /bin/command_not_found "$@" ||
		echo "${SHELL##*/}: $1: not found"
}
