#! /usr/bin/env xs

# systemd doesn't set locale, so we must...
# ref: /usr{/local}/share/doc/xs/SYSTEMD_LOCALE
~ $LC_ALL () && {
	LC_ALL = en_US.UTF-8
	LANG = $LC_ALL
	SHLVL = `($SHLVL-1)
	printf 'Locale: %s'\n $LC_ALL
	exec xs -l
}
# end locale hack

umask 0022
path = /usr/local/bin /usr/bin /usr/sbin $home/.local/bin $home/bin
history = $home/.local/share/xshistory

catch {|e|
	# Because I set autologin, an uncaught error in one of the scripts
	# can be really insidious: error causes termination, which ends
	# the session, which causes a new session to start; repeat.
	#
	# With this catcher, a "rescue" shell is spawned upon error.
	# The rescue shell does *not* load functions from the environment;
	# this breaks an error cycle caused by an incorrect definition.
	# Loading continues upon leaving the rescue shell; the failing
	# script is *not* loaded again.
	echo $e
	echo '~/.xsrc: Spawning rescue shell'
	xs -p
} {
	access -d ~/.xslib.d && {for f ~/.xslib.d/*.xs {. $f}}
	access -d ~/.xsrc.d && {for f ~/.xsrc.d/*.xs {. $f}}
}

true
