forked from strom/dotfiles
53 lines
1.6 KiB
Bash
53 lines
1.6 KiB
Bash
# vi: set ft=sh ts=4 sw=0 sts=-1 sr noet nosi tw=0 fdm=marker:
|
|
# shellcheck shell=sh disable=1090,1091,2155
|
|
|
|
# This uses environment variables from environment.d without being a systemd service
|
|
if [ -x /usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator ]; then
|
|
set -o allexport
|
|
. /dev/fd/0 <<-EOF
|
|
$(/usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator)
|
|
EOF
|
|
set +o allexport
|
|
|
|
# If there is no systemd, e.g. in containers, parse, quote and evaluate manually
|
|
elif [ -d ~/.config/environment.d ]; then
|
|
eval "$(
|
|
for fragment in ~/.config/environment.d/*.conf; do
|
|
[ -f "$fragment" ] || continue
|
|
while IFS= read -r line; do
|
|
case "$line" in
|
|
\#* | "") continue ;; # Skip comments and empty lines
|
|
*=*)
|
|
# Use coreutils printf for quoting support in POSIX sh
|
|
command -p printf 'export %s=%q\n' "${line%%=*}" "${line#*=}"
|
|
;;
|
|
esac
|
|
done <"$fragment"
|
|
done 2>/dev/null # nullglob
|
|
unset fragment key value
|
|
)"
|
|
fi
|
|
|
|
# Fallback for essential variables
|
|
set -o allexport
|
|
: "${XDG_CACHE_HOME:=$HOME/.cache}"
|
|
: "${XDG_CONFIG_HOME:=$HOME/.config}"
|
|
: "${XDG_DATA_HOME:=$HOME/.local/share}"
|
|
: "${XDG_STATE_HOME:=$HOME/.local/state}"
|
|
: "${XDG_DATA_DIRS:=/usr/local/share:/usr/share}"
|
|
set +o allexport
|
|
|
|
if [ -n "$container" ]; then
|
|
export CONTAINERENV=1
|
|
elif ! [ -d /run/systemd ]; then
|
|
if [ -e /run/.dockerenv ] || [ -e /run/.containerenv ]; then
|
|
export CONTAINERENV=1
|
|
fi
|
|
elif systemd-detect-virt --quiet --container; then
|
|
export CONTAINERENV=1
|
|
fi
|
|
|
|
#shellcheck disable=SC1090
|
|
if [ -e ~/.profile.local ]; then
|
|
. ~/.profile.local
|
|
fi
|