punktdateien-bashrc/startup.sh

78 lines
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# shellcheck disable=SC2154
# Save cwd
BASHRCD_WORKDIR=$(pwd)
[[ -z "${BASHRCD_WORKDIR}" ]] && BASHRCD_WORKDIR=${HOME}
# Cancel execution of system-wide punktdateien-bashrc if user-wide installation is detected
if [ -n "${BASHRCD_SYSTEM}" ] && [ -d "${HOME}/.bashrc.d" ] && [ -f "${HOME}/.bashrc.d/startup.sh" ]; then
unset BASHRCD_SYSTEM
return 0
fi
# Define variables
export "BASHRCD_FALLBACK=exec env --ignore-environment bash --norc --noprofile"
if [ -z "${BASHRCD_SYSTEM}" ]; then
export "BASHRCD_HOMEDIR=${HOME:?}/.bashrc.d"
else
export "BASHRCD_HOMEDIR=/etc/bashrc.d"
fi
# cd into to home directory
cd "${BASHRCD_HOMEDIR}" || (
echo ":: Can't cd into ${HOME:?}/.bashrc.d"
${BASHRCD_FALLBACK}
)
# Initialize basic stuff
[[ -f "init.d/path.sh" ]] && source "init.d/path.sh"
[[ -f "init.d/variables.sh" ]] && source "init.d/variables.sh"
[[ -f "init.d/aliases.sh" ]] && source "init.d/aliases.sh"
[[ -f "init.d/functions.sh" ]] && source "init.d/functions.sh"
# Create default configuration file
if [ ! -f "config.sh" ]; then
if [ -n "${BASHRCD_SYSTEM}" ] && [ "${UID}" != "0" ]; then
echo ":: Warning: Can't create system-wide configuration file as normal user."
else
$(which cat) << EOF >> config.sh
#!/usr/bin/env bash
# Example configuration
CONFIG_AUTOSAVE_HISTORY=1
CONFIG_BETTER_COMPLETION=1
CONFIG_CUSTOM_PROMPT=1
CONFIG_EDITOR=nano
CONFIG_FLOW_CONTROL=0
CONFIG_REPLACE_PKGMGR_ORIGINAL=pacman
CONFIG_REPLACE_PKGMGR_REPLACEMENT=paru
EOF
fi
fi
# Load configuration file
[[ -f "config.sh" ]] && source "config.sh"
# Run settings scripts
for file in settings.d/*; do
# shellcheck disable=SC1090
source "${file}"
done
# Initialize shell programs
for file in programs.d/*; do
# shellcheck disable=SC1090
source "${file}"
done
# Run startup scripts
for file in startup.d/*; do
# shellcheck disable=SC1090
source "${file}"
done
# Finish startup
cd "${BASHRCD_WORKDIR}"
unset BASHRCD_SYSTEM